how can i get search word when a visitor comes from google search to my site?
http-headers, php
Solution
Try this script:
function getKeywords()
{
$refer = parse_url($_SERVER['HTTP_REFERER']);
$host = $refer['host'];
$refer = $refer['query'];
if(strstr($host,'google'))
{
$match = preg_match('/&q=([a-zA-Z0-9+-]+)/',$refer, $output);
$querystring = $output[0];
$querystring = str_replace('&q=','',$querystring);
$keywords = explode('+',$querystring);
return $keywords;
}
else
{
return false;
}
}
Note: this does not work when the someone used encrypted Google (which uses SSL): https://encrypted.google.com/
Problem
I want to customize my index.php when a visitor searchs for a word in google search and comes to my site. ex: ``` if(visitor searches for "A" in google search) do somthing; elseif(visitor searches for "B" in google search) do somthing else; ``` if i should use referrer tell me how?