Forum Moderators: coopster

Message Too Old, No Replies

IE/ELSE mime switcher not working, no PHP errors, but not working?

         

JAB Creations

11:30 pm on Dec 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All this script is intended to do is serve mimetypes based on the useragent. I've narrowed the script down to this from it's original length to just work between Gecko and IE.

$useragent=getenv("HTTP_USER_AGENT");

if ($useragent="MSIE") {header("Content-type: text/html");}

elseif ($useragent="Gecko") {header("Content-type: application/xhtml+xml");}

Whichever condition is first gets executed and obviously isn't what I want.

jc_armor

11:45 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



you should use "==" not "=" :)

dmmh

11:51 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



better yet, '===' :p

JAB Creations

11:58 pm on Dec 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is more of an if/else problem that I've encountered before that I am not sure about.

= is an assignment...
== means if the string includes
=== means the string is exactly

$string = set string
if $string == if mygeckostring contains "gecko" text
if $string === if string contains exact string

Anyway I am using == (as I accidentally posted =). I'd prefer that if someone responds that they have tested their answer out first please.

JAB Creations

12:09 am on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok....a lucky find...

$useragent = getenv("HTTP_USER_AGENT");

if (preg_match("/MSIE/i", "$useragent"))
{
header("Content-type: text/html");
}

else if (preg_match("/Gecko/i", "$useragent"))
{
header("Content-type: application/xhtml+xml");
}

For other people's future references. :)

dmmh

6:27 am on Dec 22, 2005 (gmt 0)

10+ Year Member



= is an assignment...
== means the variable is equal to the value
=== means the variable is equal to the value AND of the same type (string, integer etc)

I use === where I can, especially when it comes to sessions, important stuff