transmothra: (aaiiighhh!!)
[personal profile] transmothra
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?

Date: 2006-02-06 07:24 pm (UTC)
From: [identity profile] mjb.livejournal.com
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

Date: 2006-02-07 02:15 am (UTC)
From: [identity profile] transmothra.livejournal.com
but it's so tiny & out of the way! & (currently) IE is so 1998.

May 2025

S M T W T F S
    123
45678 910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 4th, 2025 09:20 am
Powered by Dreamwidth Studios