transmothra: (aaiiighhh!!)
transmothra ([personal profile] transmothra) wrote2006-02-06 12:04 pm
Entry tags:

why does my browser sniffer script break all of a sudden?

my old browser sniffer that's worked so well for me for years, cobbled together from various sources, doesn't work when i upload it. funny thing is, no matter what i change, it always says the error is on line 1, which is of course the <?php delimiter. the next line is blank, and the few lines after that are comments. after that, it goes:

sniffer.php
function inAgent($agent) {
if (eregi($agent,$_SERVER['HTTP_USER_AGENT'])){
$br = true;
} else {
$br = false;
}
return $br;
}
if (!isset($browser)) {
$browser = "";
}
switch (inAgent("MSIE")) {
case true:
if (inAgent("Mac")) {$browser = inAgent("MSIE 5") ? "ie5mac" : "ie4mac";}
elseif (inAgent("Win")) {$browser = "iewin";}
break;

case false:
if (inAgent("Firefox")) {$browser = "firefox";}
elseif (inAgent("iCab")) {$browser = "icab";}
elseif (inAgent("Mozilla/5")) {$browser = "mozilla";}
elseif (inAgent("Mozilla/4"))
{
if ( inAgent('Mac')) {$browser = "nsmac";}
else {$browser = (inAgent("Win")) ? "nswin" : "nsunix";}
}
elseif (inAgent("Opera")) {$browser = "opera";}
elseif (inAgent("Safari")) {$browser = "safari";}
else {$browser = "unknown";}
break;
}

switch ($browser) {
case "iewin":
$sniffedcss1 = "absolute";
$sniffedcss2 = "top:";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!</a>";
break;

case "iemac":
$sniffedcss1 = "absolute";
$sniffedcss2 = "top";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!</a>";
break;

case "ie5mac":
$sniffedcss1 = "absolute";
$sniffedcss2 = "top";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!</a>";
break;

case "firefox":
$sniffedcss1 = "fixed";
$sniffedcss2 = "bottom";
$GLOBALS['brwsrmssg'] = "thank you for using Firefox!";
break;

case "icab":
$sniffedcss1 = "fixed";
$sniffedcss2 = "bottom";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!</a>";
break;

case "nswin":
$sniffedcss1 = "fixed";
$sniffedcss2 = "bottom";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!</a>";
break;

case "nsunix":
$sniffedcss1 = "absolute";
$sniffedcss2 = "top";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!</a>";
break;

case "nsmac":
$sniffedcss1 = "absolute";
$sniffedcss2 = "top";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!</a>";
break;

case "mozilla":
$sniffedcss1 = "fixed";
$sniffedcss2 = "bottom";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!</a>";
break;

case "opera":
$sniffedcss1 = "fixed";
$sniffedcss2 = "bottom";
$GLOBALS['brwsrmssg'] = "thank you for using Opera!";
break;

case "safari":
$sniffedcss1 = "fixed";
$sniffedcss2 = "bottom";
$GLOBALS['brwsrmssg'] = "thank you for using Safari!";
break;

default:
$sniffedcss1 = "fixed";
$sniffedcss2 = "bottom";
$GLOBALS['brwsrmssg'] = "Safer, faster, better. <a href=\"http://www.spreadfirefox.com/?q=affiliates&id=7148&t=1\">Get Firefox!!</a>";
break;
}

and i'm calling it like this:
header.php

<?
require_once ("sniffer.php");
?>

/* snip */

<img src="<? echo $_GLOBALS["direkt"]; ?>wp-content/themes/Ice/images/image.gif" style="position: <? echo $sniffedcss1; ?>; <? echo $sniffedcss2; ?>: 0px; right: 0px;" alt="description" />



footer.php
<? echo $GLOBALS['brwsrmssg']; ?>

it works perfectly locally, as it should. i'm on Apache 2.2.0 and PHP 4.4.1 (Win), whereas my host is using PHP 4.4.1 on Apache 1.3.34 (Unix).

the error i'm getting is either
Parse error: parse error, unexpected T_STRING in /real/path/to/html/sniffer.php on line 1
or ...unexpected T_FUNCTION..., depending on what i've tried to do to fix it.

i just don't get it. any ideas?

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting