SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php to control the view of css

    Hello,
    I want to create a php file to check the visitor browser and version and upon it view a certain css

    In my pages I have :
    Code:
    <style type="text/css" media="all">@import "/css/css.php?1";</style>
    in the css.php I have :
    Code:
    <?php if(ereg("\?1$", $REQUEST_URI)) {
    if (strstr (getenv('HTTP_USER_AGENT'), 'MSIE')) { 
    include "/css/ie.css";
    }
    elseif (strstr (getenv('HTTP_USER_AGENT'), 'Netscape')) { 
    include "/css/ns.css";
    }
    elseif (strstr (getenv('HTTP_USER_AGENT'), 'opera')) { 
    include "/css/opera.css";
    }
    else {
    include "/css/others.css";
    }}
    ?>
    I would like it to check the version also can anyone help?
    Also is it possible to prevent users from downloading the css if accessed css.php?1 ?
    Last edited by mahmoud; May 31, 2001 at 07:03.
    Mahmoud

  2. #2
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a problem with your code as it is? Does it not work?

    Here is what I use:
    PHP Code:
    <?

    if(eregi("msie.[4|5]",getenv('HTTP_USER_AGENT')))
        
    $browser "msie";
    // Netscape Navigator?
    else if(eregi("nav",getenv('HTTP_USER_AGENT')) or eregi("moz",getenv('HTTP_USER_AGENT')))
        
    $browser "nav";
    else
        
    $browser "other";

    if(
    $browser=="msie")
        print 
    "<LINK REL=StyleSheet HREF=\"ie.css\" TYPE=\"text/css\">";
    else
        print 
    "<LINK REL=StyleSheet HREF=\"ns.css\" TYPE=\"text/css\">";

    ?>
    And yes if you store call your CSS like that through an external php file you should prevent the user from ever seeing the CSS filename. But you will not prevent the really adamant webmaster from seeing your styles-- it's easy to look in your browser cache, sort by time updated, and find which CSS file was yours.
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  3. #3
    SitePoint Enthusiast mahmoud's Avatar
    Join Date
    May 2001
    Location
    Egypt
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    - The code works, but for all versions of IE, NS ..

    Users using IE 6 won't C your style ie.css and will C ns.css

    I want to add ( =<4 ) for IE
    and ( =<6 ) .. so I won't change every time there is a new version

    - And Also the users can C the stylesheet
    if they went to the php file ..
    Mahmoud


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
  •