Categories
uncategorized

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?

By jae

jae lethe (he/she/they) is a blogger, musician, artist, poet, web developer/designer, armchair philosophizer, teller of tales, and gadabout. Also, something he calls a "behavioral artist." (Not sure.) She has plans. BIG plans.

Among the things that he has done for a laugh are minor fractures, cuts, scrapes, and various scabs. Though she's quick to point out that they're no imbecile, we're fairly certain that he thinks the word means some kind of medieval pharmacist.

This is her latest home on teh internets - where jae stores their swear words, when they're not hurling them at the sun in vain.

2 replies on “why does my browser sniffer script break all of a sudden?”

chop out chunks of code till it works, so you can isolate the actual section that’s giving you problems? ps nagging people to change browsers is lame

Comments are closed.