help with isolated php failure

He has: 688 posts

Joined: Feb 2001

This is a spin-off of my other thread. I've got some code php code that determines the browser and then gives you different output according to the browser. Here's the code:

Quote:

<?

{ global $HTTP_USER_AGENT;
if(strstr($HTTP_USER_AGENT, "MSIE 6")) {
$check = "good";
$browser = "MSIE6";} // MSIE6
else if(strstr($HTTP_USER_AGENT, "MSIE 5")){
$check = "good";
$browser = "MSIE5";} // MSIE5
else if(strstr($HTTP_USER_AGENT, "MSIE 4")){
$check = "bad";
$browser = "MSIE";} // MSIE4
else if(strstr($HTTP_USER_AGENT, "Netscape6")){
$check = "good";
$browser = "NS6";} // NS6
else if(strstr($HTTP_USER_AGENT, "Mozilla/4")){
$check = "bad";
$browser = "NS4";} // NS4
else if(strstr($HTTP_USER_AGENT, "Mozilla/5")){
$check = "bad";
$browser = "Mozilla";} // Mozilla
else if(strstr($HTTP_USER_AGENT, "Opera/6")){
$check = "bad";
$browser = "Opera";} // Opera
else {
$check = "bad";
$browser = "Unknown";} // Unknown
};

print "Browser Check:".$check;

print "Browser Type:".$browser;

if ($check = "good") {
print "this is a print of a good output";
} else {
print "this is a print of a bad output";
}

?>

When using NS4.7, the first print line outputs that the browser check is "bad". That's correct. The next print line outputs that the browser type is NS4. This is also correct, but not really relevant. The next section says if the browser check is good, print the good output - and if anything else, print the bad output. Since we know that the browser check ($check) is working properly and comes up as "bad", why does my code function incorrectly and give you the good output that should only work if browser check was good? Any wierd failures should end up in the "else" section? What went wrong?

You can see the script work properly in MSIE5 but fail in NS4: mikesussman.com/2.php

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Are you setting the variable or checking it?

$variable = "value"; // set
$variable == "value"; // comparison

?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I remember it like this:

$variable = "value"; is "this variable is value."

$variable == "value"; is "this variable is equal to value."

He has: 688 posts

Joined: Feb 2001

Thank you! That was it. I knew it would be easy for somebody smarter than me Laughing out loud

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

psht. fresh eyeballs is all.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.