Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2005
    Location
    Hell
    Posts
    75

    Exclamation PHP script help, different CSS for different browsers...

    When I was designing my layout for my site, I ran into some CSS positioning problems...the trouble was things were completely whacked in IE. So instead of wasting my time trying to figure out what the crap was wrong, I just decided I'll use different CSS for different browsers. So, whenever a user views my site in IE, special IE CSS is printed, but if they view it in any other browser, they get the CSS that works for them. But of course, another problem came up...at my school today, I went to my site to show off to some n00b HTML authors, and guess what? The site was as messed up as ever on IE. What on earth wrong? I'm using the latest version of IE on my computer (excluding IE 7 Beta...), and I'd assume the school is too, right? But then why does everything look messed up over there? Same browser, same resolution. Only difference is they use XP, I use 2000. Some help please

    PHP Code:
    <?php
        $browser 
    $_SERVER['HTTP_USER_AGENT'];
         if(
    $browser == 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; PeoplePal 3.0)') {
          include(
    '/home/neobpal/public_html/stylesheets/main_ie.php');}
         elseif(
    $browser == 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.0; .NET CLR 1.1.4322; PeoplePal 3.0') {
          include(
    '/home/neobpal/public_html/stylesheets/main_ie.php');}
         elseif (
    $browser == 'Mozilla/4.0 (compatible; MSIE 4.0; Windows NT 5.0; .NET CLR 1.1.4322; PeoplePal 3.0'){
          include(
    '/home/neobpal/public_html/stylesheets/main_ie.php');}
         else {
             include(
    '/home/neobpal/public_html/stylesheets/main.php');
              }
    ?>

  2. #2
    Join Date
    Mar 2004
    Location
    Toronto, Canada
    Posts
    122
    Are you sure that it is outputting the sheet you made for IE? You have the user agents spelled out in long form, what if the version they use give a slightly differnt string for the user agent? You will get the 'normal' CSS file instead of the IE one.

    I am not super familiar with all the different possiblities that can be reported for user agents but that was my first though.

  3. #3
    Join Date
    Feb 2003
    Location
    L.A. C.A.
    Posts
    346
    Your code is right in a sense but only affects your browser, you shouldn't be looking at OS, you should more focus on the Browser and pick out common parts. For all 3 of your if statements there is a MSIE located somewhere within the string, this means Microsoft Internet Explorer (duh? ).

    Anyway, A much simpler peice of code would be.

    PHP Code:
    <?php
    $css_file
    =(stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))?'/home/neobpal/public_html/stylesheets/main_ie.php':'/home/neobpal/public_html/stylesheets/main.php';
    include(
    $css_file);
    ?>
    The operation inside the include brackets is the same of an if statement, the strstr searches the user_agent for MSIE, if its found it will include main_ie.php otherwise just main.php. I hope this works for you.
    WLKNS.co - A collection of my programmer thoughts

  4. #4
    Join Date
    Dec 2005
    Location
    Hell
    Posts
    75
    Ah, thank you. I had just realized that it included the OS in there, and I was looking for a way around that...then I saw your post. Thanks

Posting Permissions

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