Help With $_SERVER['HTTP_REFERER']

Discussion in 'PHP' started by DjZoC, Apr 10, 2010.

  1. #1
    hello there,
    can someone tell me how i can make this command

    <?php
    $website_referer = $_SERVER['HTTP_REFERER'];
    if ($website_referer != "http://www.google.com") { echo 'None'; } else { echo 'Google Referer'; }

    ?>

    example: http://www.google.com/search.php .... = echo 'Google Referer';
    i try http://www.google.com* but is not working ...

    can someone tell me how i can fix this command

    thanks
     
    DjZoC, Apr 10, 2010 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    take a look at parse_url()
    That should be all you need and then just match the host name which should be www.google.com
     
    JAY6390, Apr 10, 2010 IP
  3. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    
    <?php
    $website_referer = $_SERVER['HTTP_REFERER'];
    if (stristr($website_referer,"google.com") { echo 'None'; } else { echo 'Google Referer'; }
    
    ?>
    
    PHP:
     
    guardian999, Apr 10, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    <?php
    $website_referer = preg_replace('~^www\.~', '', parseurl($_SERVER['HTTP_REFERER'], PHP_URL_HOST));
    if ($website_referer != "google.com") {
    echo 'None';
     } else { 
    echo 'Google Referer'; 
    }
    
    ?>
    PHP:
     
    danx10, Apr 11, 2010 IP
  5. David3

    David3 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I like guardian999's idea. I'm sure danx10's idea works, too.
     
    David3, Apr 11, 2010 IP
  6. vosh

    vosh Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    mm....useful for me...
     
    vosh, Apr 12, 2010 IP