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 badges5 Answers
Reset to default 3You 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条)