User Agent condition

Discussion in 'PHP' started by bonjurkes, Aug 8, 2008.

  1. #1
    Hello,

    There is a non working part at my website if you visit website using Internet Explorer. So instead of showing that non working part white i decided to make a condition statement so if visitor is using internet explorer they will see another stuff there instead of real content.

    So the code should be like

    if user agent is internet explorer

    show this content

    else

    the real content



    But i couldn't manage to make it as condition for useragent. Can someone help me please?
     
    bonjurkes, Aug 8, 2008 IP
  2. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Try this
    Create a file called ifiexplore.php and place the content that you want iexplore users to see
    Create a file called main.php and place the content all the other browsers will see

    then on main page paste this code

    
    <?php
    
    if ($IE && $IEV <= 5.5)
    {
        include('ifiexplore.php');
    } 
    else
    {
    	include('main.php');
    }
    ?>
    
    PHP:
     
    jpinheiro, Aug 8, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    ^ That looks kinda incomplete to me.
     
    nico_swd, Aug 8, 2008 IP
  4. bonjurkes

    bonjurkes Well-Known Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #4
    it is showing only main.php even you visit the page via iexplorer
     
    bonjurkes, Aug 8, 2008 IP
  5. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #5
    what is the page
     
    jpinheiro, Aug 8, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Take a look at your code. You have 2 undefined variables... it cannot work this way.
     
    nico_swd, Aug 8, 2008 IP
  7. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #7
    ok i dee what you mean but how an i define the user agent?
     
    jpinheiro, Aug 8, 2008 IP
  8. payu

    payu Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    try this ...
    
    <?php
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
      // ...do IE stuff...
    } else {
      // the real content.
    }
    
    ?>
    
    
    PHP:
     
    payu, Aug 8, 2008 IP