Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-06-2009, 07:53 PM   PM User | #1
levani
Regular Coder

 
levani's Avatar
 
Join Date: Mar 2009
Location: Georgia
Posts: 183
Thanks: 29
Thanked 1 Time in 1 Post
levani is an unknown quantity at this point
If internet explorer 8

How can I get information whether an user uses internet explorer 8 or not? I use this code for IE 6, but it doesn't seem to work on IE 8.

PHP Code:
<?php
//if the browser is Microsoft IE
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
if (
ereg('MSIE 6',$_SERVER['HTTP_USER_AGENT']))
   include (
TEMPLATEPATH '/form_ie.php');
} else {
    include (
TEMPLATEPATH '/form_other.php');
}
?>
What I want to do is to execute different code if user comes from IE6 or older and different for all other browsers (including IE 7 and 8).

Any ideas?
levani is offline   Reply With Quote
Old 05-06-2009, 08:04 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
This might help ...

http://www.php-scripts.com/20050912/12/

I'm guessing you can alter [0-9] to [0-6] or [7-9] to pick out the version you want.
mlseim is offline   Reply With Quote
Old 05-06-2009, 08:04 PM   PM User | #3
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
You did change that '6' to an '8' there, right?

Anyway, the surefire way is to use conditional comments in your html, but that means that you will need at least two http-requests until you get that browser information into your server side script.
venegal is offline   Reply With Quote
Old 05-06-2009, 08:19 PM   PM User | #4
levani
Regular Coder

 
levani's Avatar
 
Join Date: Mar 2009
Location: Georgia
Posts: 183
Thanks: 29
Thanked 1 Time in 1 Post
levani is an unknown quantity at this point
My code above works as it must be on every browser, but IE8. On IE8 it doesn't include neither "form_ie.php" nor "form_other.php". Why?

I want it to include form_other.php if the browser is IE8...
levani is offline   Reply With Quote
Old 05-06-2009, 08:50 PM   PM User | #5
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
Ok, I see the problem. What you are doing is:

Are you an IE? If yes, are you IE6? Then you get form_ie.
Oh, you're not an IE? Then you get form_other.

No IE, except 6, will ever get anything included.

If you want only IE6 to get form_ie and every other browser form_other, do it like this:

PHP Code:
if (ereg('MSIE 6',$_SERVER['HTTP_USER_AGENT'])){
   include (
TEMPLATEPATH '/form_ie.php');
} else {
    include (
TEMPLATEPATH '/form_other.php');

venegal is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:36 PM.


Advertisement
Log in to turn off these ads.