PHP referrer code

Discussion in 'PHP' started by almir, Jul 31, 2008.

  1. #1
    I need some help with PHP code. I have popup on my site, but want to exclude it if visitor comes from certain site. How can I do that ?
     
    almir, Jul 31, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    if (!empty($_SERVER['HTTP_REFERER']) AND $parts = @parse_url($_SERVER['HTTP_REFERER']))
    {
        $blocked_hosts = array('some.com', 'site.com', 'blah.com');   
        $host = preg_replace('~^www\.~', null, strtolower($parts['host']));
    
        if (!in_array($host, $blocked_hosts))
        {
            // Request comes from one of the sites that's NOT in the array above.
        }
        else
        {
            // You know the deal
        }
    }
    
    PHP:
     
    nico_swd, Jul 31, 2008 IP
  3. almir

    almir Peon

    Messages:
    1,104
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Muchas Gracias
     
    almir, Jul 31, 2008 IP