Help w/Full Featured PHP Browser Detection + CSS style sheet
fabwebdesigns
Status: New User - Welcome
Joined: 21 May 2008
Posts: 1
Reply Quote
Hello
First let me say the scripts you guys provide ROCK!

I'm trying to use the Full Featured PHP Browser Detection script obtained from this web site. Also I'm using it in Dreamweaver.

[link]

I have the php code loaded via a library before the [head] section.
:: Code ::
<?php include('browser_detection.lib'); ?>


In the body section for testing I put the following:
:: Code ::

<?php
echo ( browser_detection( 'number' ) .'<br>'.
browser_detection( 'browser' ) .'<br>'. 
browser_detection( 'os' ) .'<br>'. 
browser_detection( 'os_number' ) );
?>

Outputs (browser version, browser, os, os number):
1.5
moz
nt
5.1

<?php
if ( ( browser_detection( 'browser' ) == 'ie' )
&&
( browser_detection( 'number' ) >= 5 ) )
{
echo 'it is Internet Explorer ' .
browser_detection( 'number' );
// or anything else you want to happen of course
}
?>


In testing it returned data for the browser. YEAH! as one Def Leppard's great albums and my reaction to see it work.

Since I know the code works you guys provide, my next step was to try and get it to work in the [head] section.

In the [head] section the problem I'm having is calling the correct CSS Style Sheet. What am I doing wrong below? I'm getting an error. Thanks in advance.

Here's my code:

:: Code ::

<?php
if (( browser_detection( 'browser' ) == 'ie' )
{
<link rel="stylesheet" href="stylesIE.css" type="text/css" />
}
elseif ( ( browser_detection( 'browser' ) == 'saf' )
{
<link rel="stylesheet" href="stylesSAF.css" type="text/css" />
}
else
{
<link rel="stylesheet" href="stylesOthers.css" type="text/css" />
}
?>

Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Glad you liked the script, however, without the error data there's not much anyone can do to help.

Post the exact error code and we'll see.

Generally it's neater to use switch than if/elseif, and to only call the test function one time to make it more efficient:

:: Code ::
<?php

$user_browser = browser_detection( 'browser' );

switch ( $user_browser )
{
    case 'ie':
       $stylesheet = 'stylesIE.css';
        break;
    case 'saf':
       $stylesheet = 'stylesSAF.css';
        break;
    default:
       $stylesheet = 'stylesOthers.css';
        break;
}
?>
<link rel="stylesheet" href="<?php echo $stylesheet; ?>" type="text/css" />

Back to top
Display posts from previous:   

All times are GMT - 8 Hours