javascript - how to check if a url is typed or coming from a click in php? - Stack Overflow

is there a way for php to tell if an address is directly typed by user or ing from a click or any other

is there a way for php to tell if an address is directly typed by user or ing from a click or any other method that in the end will result a php-generated page?

this question is purely out of curiosity so the urgency is very, very low. but thank you if you want to spare sometime to answer. :D

is there a way for php to tell if an address is directly typed by user or ing from a click or any other method that in the end will result a php-generated page?

this question is purely out of curiosity so the urgency is very, very low. but thank you if you want to spare sometime to answer. :D

Share Improve this question asked Aug 10, 2011 at 11:07 dqiudqiu 3372 gold badges6 silver badges15 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 3

You could use $_SERVER['HTTP_REFERER']. It should be set to the page that referred the user to your page. If the user typed the address in, it will be empty.

However, beware, it is not reliable, and can be easily modified by the user. As the PHP doc says, you can't really trust it.

In general, you can't.

0) typed (or copy-pasted!) links - REFERER will be empty

1) links clicked on a webpage - REFERER will be set

2) links clicked in an email client (not web based like gmail) - REFERER will be empty

3) links loaded as a home page - REFERER will be empty

4) links loaded from bookmarks - REFERER will be empty

So using PHP $_SERVER['HTTP_REFERER'] variable you can only distinguish case 1 from all the other cases...

You can look at the http_referrer, for a webpage loaded by directly typing in address bar it should not have any referrer but the page that was loaded by some click will have a referrer.

Using http_referrer for this purpose is very unreliable. HTTP_REFERRER is empty when the user types the URL in some browsers. It is NULL in Chrome 19, it is NOT NULL in IE8.

$direct = (bool)$_SERVER['HTTP_REFERER'];

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744331770a4568921.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信