Log in

View Full Version : HTTP_REFERER check help



dspiessens
07-16-2009, 06:01 PM
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?



<?
$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";
?>

thetestingsite
07-16-2009, 06:34 PM
Try using in_array (http://www.php.net/in_array) like so:



<?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.