Get the referrer url, site url from google search

Hello Friends,

        I need some help. Please help me to get 

      1. Which keyword is searched from the google for my site
      2. Which time it is searched?
      3. Referrer URL
       4. The link redirects to which page url of my site.

Please help me.

Thanks a lot.

Hi Priya,

Welcome to sitepoint forums!

I think that is only possible from your site and it is easier to write the code if your site has single entry. If I am not wrong, you can get three of those data from the HTTP referrer which is available in $_SERVER in PHP. So try:


echo $_SERVER["HTTP_REFERER"];

and see what it will print. It will have the whole URL that was in the browser’s address bar after someone searches with some keywords.

But for the time I think you have to track it when they enter into your site. So it will be your the time of your server not directly from the google when they searched.

I am not sure if there are other ways to track that. Would be great if there are some other ways too.

Thanking you.

Hi Sir,

   Thank u so much for ur reply.  
   But i need the time which is nothing but which time the keyword is searched in google.

for example, if we type “nature” in google, i expect the following result like

  1. google results’ top url - http://www.google.co.in/#hl=en&expIds=17259,26767&xhr=t&q=nature&cp=3&pf=p&sclient=psy&aq=0&aqi=&aql=&oq=natu&gs_rfai=&pbx=1&fp=b63669bddff54f57

  2. i have searched at 5.23(time)

  3. which keyword is searched like “nature”

the above 3 things also needed for me.

Thanks a lot.

Try this:


<?
$keyword = '';
		$time = 0;
		if (isset($_SERVER['HTTP_REFERER']))
		{
			if (preg_match('/(www\\.)?google\\./', $_SERVER['HTTP_REFERER']))
			{
				if (($query = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY)) != NULL)
				{
					$arr = array();
					parse_str($query, $arr);
					print_r($arr);
					if (isset($arr['q'])) $keyword = $arr['q'];
					$time = time();
				}
			}
		}
		echo 'Searched: for &quot;'.$keyword.'&quot; on '.date('d.m.Y H:i:s', $time);
?>

Enjoy!

EDIT: Do a print_r($_SERVER); on your page to see various useful variables.

Hello Sir,

Thank u so much sir. I will try this and let u know.

Once again thanks a lot.

Remember priya, in the code that Steve has provided, the time is the time of your server when the user enters into your website but not the time of search in google. Lets suppose one searches in Google at 10am and clicked the link after 30 minutes then the time will be of 10:30am not 10am. Hope it is clear.

You can’t obtain url after hash # via HTTP_REFERER.
Google search changed to ajax, and its url are now unreadable.
after # is generated by javascript (only on client side), and only this way you can obtain it. Mabe Google sends their parameters by POST now, I don’t know anything about it.