I'm trying to check if a visit to my page is from any search engines (google, yahoo, ask etc...). For example, if someone goes on www.google.com and searches "best dog food store" and my website shows up in the results, and the user clicks on that link. I want to validate that user with the following.
What i am doing right now is checking the HTTP referer, and from that, validating if it contains any string from an array, like so:
$_is_from_search_engine = false;
$_search_engine_list = [
'www.google.com',
'google',
'www.yahoo.com',
'yahoo'
];
if(isset($_SERVER['HTTP_REFERER'])){
foreach($_search_engine_list as $search) {
if (strpos($_SERVER['HTTP_REFERER'], $search) !== false){
$_is_from_search_engine = true;
}
}
}
If $_is_from_search_engine
is TRUE, i am going to display a popup, but that's irrelevant.
My question would be, is this an ok way to do it? Is there a more practical way of doing this, does this have any flaw? Thanks in advance for any tips.