Results 1 to 2 of 2

Thread: HTTP_REFERER check help

  1. #1
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HTTP_REFERER check help

    Hi all,
    I'm a newbie to php and programming for that matter. I have a script on my page that is suppose to check what page in my site the user came from. If the user came from 1 of 4 specific pages, then something will display. This is what I have so far, but it is not working correctly. It is saying that I came from a blue page even when I did not. Does anyone know what I am doing wrong?

    Code:
    <?
    $blue_pages[] = "blue1.php";
    $blue_pages[] = "blue2.php";
    $blue_pages[] = "blue3.php";
    $blue_pages[] = "blue4.php";
    
    if ( $_SERVER['HTTP_REFERER'] == $blue_pages )
    echo "You came from a blue page";
    else
    echo "You DID NOT come from a blue page";
    ?>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try using in_array like so:

    Code:
    <?php
    $blue_pages = Array('blue1.php', 'blue2.php', 'blue3.php', 'blue4.php');
    
    echo (in_array($_SERVER['HTTP_REFER'], $blue_pages)) ? 'You came from a blue page' : 'You DID NOT come from a blue page';
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

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