Question

I'm using PHP and I'd like to create an if statement that does something if the user came to the current page from the home page. So far, I've been using this code:

if(!in_array($_SERVER['HTTP_REFERER'], $validHomes){
//do something}

The array $validHomes contains a couple different variations of index.php (without .php, without www.)

This has been working fine but now I'd like the home page to have a GET variable sometimes which will have different values: www.example.com/index?var=5. $_SERVER['HTTP_REFERER'] treats URLs with GET variables that have different values as different from each other so I'm wondering if anyone has a suggestion for how to get around this? How can I trigger the if statement for a wide range of index URLs that contain GET variables with different values?

Thanks a lot for any help.

Was it helpful?

Solution

It would be better to add a GET parameter from your home page links and check for that parameter instead. This would be far simpler and more reliable.

OTHER TIPS

Another option would be to use stristr($_SERVER['HTTP_REFERER'], 'index');

Though Matt's answer is indeed more reliable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top