SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Browser detect and .css

    I found this code over at PHPBuilder.com and am attempting to impliment it. If I echo the $style variable at the end it returns the correct .css file reference depending on which browser I'm using but the stylesheet itself is not being recognized. I think the inline PHP code is the problem because if I change this:
    <link rel="STYLESHEET" href="<?php $style; ?>" type="text/css">
    To this:
    <link rel="STYLESHEET" href="style.css" type="text/css">
    the style.css file is recognized. Here's the code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>Test Browser Detect</title>
    <?php

    function find($component) {
    global $HTTP_USER_AGENT;
    $result = stristr($HTTP_USER_AGENT,$component);
    return $result;
    }

    if ( find('MSIE 4') or find('MSIE 5') ) {
    if ( find('Mac') ) {
    $style = ( find('MSIE 5') ) ? 'style.css':'stylemac.css';
    }
    elseif ( find('Win') ) {
    $style = 'style.css';
    }
    }
    elseif ( !find('MSIE') ) {
    if ( find('Mozilla/5') or find('Mozilla/6') ) {
    $style = 'stylenswin.css';
    }
    elseif ( find('Mozilla/4') ) {
    if ( find('Mac') ) {
    $style = 'stylemac.css';
    }
    elseif ( find('Win') ) {
    $style = 'stylenswin.css';
    }
    else {
    $style = 'stylensunix.css';
    }
    }
    }

    ?>
    <link rel="STYLESHEET" href="<?php $style; ?>" type="text/css">

    </head>

    <body>

    <H1>test is MSIE</H1>
    <div>test is blue</div>
    <H1>test is Netscape</H1>


    </body>
    </html>

    It's too bad this is even necessary but.....any thoughts?

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <link rel="stylesheet" href="<?php echo("$style"); ?>" type="text/css" />
    You just needed the PHP to do something. Try that -- the echo will take care of it.

    Happy coding!
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  3. #3
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey that worked! Thanks much. Now on to all those messy Netscape vs. IE issues.

  4. #4
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem. Have fun!

    See you around the forums!
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •