Get Original Referrer URL from Google Search with PHP?

628

I am using$_SERVER['HTTP_REFERER'];, to getting Referrer URL.

When I typed in Google search box theq='some text'

`https://www.google.com.pk/#hl=en&output=search&sclient=psy-ab&q=some text%2Ftestbulkresponse&oq=some text%2Ftestbulkresponse&gs_l=hp.3...15460.24280.1.25007.30.30.0.0.0.0.325.7136.2-27j3.30.0...0.0...1c.1.8.hp.dAvuch3bBg4&psj=1&bav=on.2,or.r_qf.&bvm=bv.44697112,d.ZWU&fp=980e418276b62e8c&biw=1366&bih=595`

but when I get this URL on my website using as$_SERVER['HTTP_REFERER'];

theq=null like this

`http://www.google.com.pk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CC0QFjAA&url=http%3A%2F%2Fwww.bulkresponse.com%2Ftestbulkresponse%2Fdashboard.php&ei=r9NbUfv7GcjaOYDdgKgC&usg=AFQjCNF9U_DpJEwupZ0ZLPbjWJ6DQLWZcA&bvm=bv.44697112,d.ZWU`. 

So I am unable to get searched keywords in Google, what should I can do to get searched keywords?

425

Answer

Solution:

Google removes the search query for HTTPS connections and logged users so the only way to know the search query is using Google Analytics

When you search from https://www.google.com, websites you visit from our organic search listings will still know that you came from Google, but won't receive information about each individual query.

http://googleblog.blogspot.com.es/2011/10/making-search-more-secure.html http://analytics.blogspot.com.es/2011/10/making-search-more-secure-accessing.html

612

Answer

Solution:

Try this.

parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $queries);

echo $queries['q'];

References:

http://php.net/parse_url

http://php.net/parse_str

110

Answer

Solution:

$ref = $_SERVER['HTTP_REFERER'];
if(strstr($ref, "google.com")){
  //echo $ref;  
  $regex ='/q=(.+?)&/';
  preg_match($regex, $ref, $query);
  echo $query[1];
 }

it doesn't work everytime, especially now with their updates. I get " &esrc=s " reported a lot.

People are also looking for solutions to the problem: php - Not able to upload image in Magento Backend Admin

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.