开发者

Checking for searched keyword

On one page of my website, I am getting a lo开发者_开发知识库t of visitors from a specific keyword. I want to display a message for only those visitors coming from that search keyword. How can I check if the user is coming from the search engine / that keyword?


you need to parse the $_SERVER['HTTP_REFERER']

this link explain good how to parse it

http://www.stevenyork.com/tutorial/how_to_get_search_engine_referal_keywords_using_php


Parse $_SERVER['HTTP_REFERER'] but bear in mind that it is optional whether a browser supplies this information. Also, as user submitted data, it should be considered subject to tampering.

C.


$_SERVER['HTTP_REFERER'] should give you the data that you are looking for. You can run it against a regular expression like \?.+foo if 'foo' is the keyword that you are looking for. the regular expression is not super reliable as it will match any referring site with the keyword in the query string but it should be good enough. It does have the advantage of matching any search engine and not just focusing on a set list as most scripts of this type do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜