Browser Cloaking

Discussion in 'PHP' started by Ithilnet, May 1, 2007.

  1. #1
    How do I cloak based on the browser?

    For example,

    if visitor is running IE
    execute this code
    else
    execute another

    Thanks
    Ithilnet
     
    Ithilnet, May 1, 2007 IP
  2. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if (stripos('msie', $_SERVER['HTTP_USER_AGENT']) !== false) {
        // IE
    } else {
        // Everything else unless you wanna be more specific
    }
    PHP:
    I think
     
    decepti0n, May 1, 2007 IP
  3. venetsian

    venetsian Well-Known Member

    Messages:
    1,105
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    168
    #3
    <?php
    function _get_browser()
    {
     $browser = array ( //reversed array
      "OPERA",
      "MSIE",            // parent
      "NETSCAPE",
      "FIREFOX",
      "SAFARI",
      "KONQUEROR",
      "INTERNETSEER"
     );
     
     $info[browser] = "OTHER";
      
     foreach ($browser as $parent)  
     {
      if ( ($s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) !== FALSE )
      {            
        $f = $s + strlen($parent);
        $version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
        $version = preg_replace('/[^0-9,.]/','',$version);
                  
        $info[browser] = $parent;
        $info[version] = $version;
        break; // first match wins
      }
     }
     
     return $info;
    }
    $info=_get_browser();
    $browser=$info[browser];
    ?>
    PHP:
    That returns on variable $browser very friendly value and "MSIE" is Internet Explorer

    Cheers,

    Venetsian
     
    venetsian, May 1, 2007 IP
  4. Kendothpro

    Kendothpro Well-Known Member

    Messages:
    574
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Keep in mind that anybody can fake his useragent so it is not to trust 100% for security / sensitive stuff
     
    Kendothpro, May 1, 2007 IP
  5. venetsian

    venetsian Well-Known Member

    Messages:
    1,105
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    168
    #5
    If he needs to cloak that's good, but if you're trying to do SEO Cloaking then better use IP lists .. otherwise you can get banned so badly ...

    Cheers,

    Venetsian.
     
    venetsian, May 1, 2007 IP
  6. Kendothpro

    Kendothpro Well-Known Member

    Messages:
    574
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    120
    #6
    I actually made it a habit to surf using "Googlebot" as my useragent :D
     
    Kendothpro, May 1, 2007 IP
  7. Ithilnet

    Ithilnet Peon

    Messages:
    167
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Naa it isn't for search engine cloaking. I have a site that has troubles with IE and the css style and I need to display another design.

    Thank you very much!
     
    Ithilnet, May 1, 2007 IP