Page 1 of 1

PHP Include w/If IE Condition Statement?

Posted: Sun Oct 18, 2009 12:28 pm
by Alan Horvath
I was having a problem with Internet Exploder (big surprise, right?) displaying my drop down menus improperly. I found a solution that works ... I have a PHP file that I place as an include on all my pages and the drop down menus, on IE, are cool.

But my problem, at present, is this:
I need to have that PHP Include (for IE) loaded, in place of my regular PHP Include (for all the other browsers), when some one is using the IE browser.

Is there a way to write an "If IE" conditional statement for a PHP Include?

Thanks for your help!

Alan

Re: PHP Include w/If IE Condition Statement?

Posted: Sun Oct 18, 2009 2:43 pm
by califdon
You can normally determine what browser is being used with the $_SERVER['HTTP_USER_AGENT'] variable. See http://php.about.com/od/learnphp/p/http_user_agent.htm. You will probably have to parse the string to determine the value you need.

Re: PHP Include w/If IE Condition Statement?

Posted: Sun Oct 18, 2009 6:20 pm
by Alan Horvath
Thanks, Jack. I might be missing it, but I don't see the solution I'm looking for via the link you gave me.

What I'm looking to do is to display my drop-down menus with a PHP include, like this:
<?php include "MyMenus.php"; ?>

But I want to redirect IE browsers to a different include:
<?php include "MyMenus_IE.php"; ?>

So is there a way I can tell all browsers to read <?php include "MyMenus.php"; ?>, but have IE browsers *not* read that one and be redirected to <?php include "MyMenus_IE.php"; ?> instead?

I've tried:
<!--[if IE]>
<?php include "MyMenus_IE.php"; ?>
<![endif]-->

But that doesn't work.

Thanks for your time.

Alan

Re: PHP Include w/If IE Condition Statement?

Posted: Sun Oct 18, 2009 6:42 pm
by Alan Horvath
What about this? Can you explain what he means when he says ... "You will have to make sure that the code is filled under the first line of code on your PHP page." ... ?
-------------------------------------------------------
It is an simple example wich will take the visitators to one page if they are using Internet Explorer, and to another page if the visitator is using another tipe of browser.

Now lets decide what is going to happen if:

1. If the browser is Microsoft Internet Explorer (MSIE), it will automaticaly redirect to: http://www.tutorialize.org/redirect1 ( example )
2. If the browser is not Microsoft Internet Explorer (MSIE), it will automaticaly redirect to: http://www.tutorialize.org/redirect2( example )

The most interesting part of this is that this code is, that it has to be sent out before any output to the HTML page. You will have to make sure that the code is filled under the first line of code on your PHP page.

This is the example php code, it can be modified in many ways to fill your requests.


//if its MSIE then

if
(
$name
= strstr
(
$HTTP_USER_AGENT
, "MSIE"
)
)

{

//it will send to http://www.tutorialize.org/redirect1

Header
(
"Location: http://www.tutorialize.org/redirect1"
)
;
}

else

{

//else will send to http://www.tutorialize.org/redirect2

Header
(
"Location: http://www.yahoo.com/"
)
;
}
-------------------------------------------------------
Alan

Re: PHP Include w/If IE Condition Statement?

Posted: Sun Oct 18, 2009 7:10 pm
by Alan Horvath
Ah-haaa! I found one that works!

This goes into "index.php" ... and *nothing* else:
----------------------------------------------------
<?php
if (eregi("MSIE", $_SERVER['HTTP_USER_AGENT']))
{ $location = 'http://somesite.com/index_ie.php';
header ("location: $location");
exit();
} else {
$otherlocation = 'http://somesite.com/index_allothers.php';
header ("location: $otherlocation");
exit();
}
?>
----------------------------------------------------

HalleluYah!

Alan