I would like to know which search engine and what particular query led a user to my site. I have partially solved this problem. I can determine from what search engine the user has logged in to the site. But I am not able to find out what query has been used.
This is what I have so far:
$R=$_SERVER['HTTP_REFERER'];
echo "<br />this 1^".$R;
$A=$_SERVER['REMOTE_ADDR'];
$U=$_SERVER['REQUEST_URI'];
$R=urldecode ($R);
echo "this IP - ".$A."<br>";
echo "this - ".$U."<br>";
if (strpos($S, "yandex") != 0) {
preg_match('"text=(.*?)[^&]*"', $S, $arr);
echo "this ".$arr[1];
}
elseif (strpos($S, "google") != 0) {
preg_match('/q=(.*)&/sei', $S, $arr);
echo "this Google ".$arr[1];
}
elseif (strpos($S, "rambler") != 0) {
preg_match('"query=(.*?)[^&]*"', $S, $arr);
echo "this Rambler ".$arr[1];
}
else {
echo "this ".$R;
}
echo "<br />this ^^".$R;
echo "<br />this ^^".$R;
All $_SERVER ['HTTP_REFERER']
appears to be encoded like this:
this ^^http://www.google.ru/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CB8QFjAA&url=http%3A%2F%2Fxn--80aag0ab4aqcid.xn--p1ai%2F&ei=YuDxU6L3PKPMyAO-3ID4Aw&usg=AFQjCNHUtFnVLIHqgsuC9skqk8Qje9K3Bg&sig2=12UXCtusUAr5pvAQGxb_Hg
How can I find out what search query led the user to my site?