Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Address bar input vs. Link

Is there a way to interrogate a request to determine the method of navigation ?

(using a LAMP configuration, PHP)

In other words... I would like to know whether the entry was hand typed into the address bar, or a link/bookmark was used.

like image 290
eleete Avatar asked Dec 01 '25 21:12

eleete


2 Answers

You can check the $_SERVER['HTTP_REFERER'] variable which will contain the URL the person has navigated from. I'm not sure what happens if they choose a bookmark or enter the URL manually, though I suspect that this variable would be blank.

Though, as it says in the manual:

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

like image 113
nickf Avatar answered Dec 04 '25 10:12

nickf


Reliably, you can not.

One method you could try is referer headers (which is how it's spelled in the spec), usually sent by the browser to indicate where the user is coming from. In PHP, this is available in $_SERVER['HTTP_REFERER'].

Most modern browsers (I've tested Google Chrome and Firefox) send a referer header on link clicks and not on direct entry - that is, if the user's settings say to, which they usually do by default.

Another option, depending on just how much you really care, is to append some sort of randomly-generated session variable to the URL in the link and, on receiving a request, see if the token in the URL matches the token in the user's session. If so, there you go. If not, this link was copy-pasted.

Of course, all of these methods can easily be beaten, and your server can be fooled. Don't depend on them.

like image 34
Matchu Avatar answered Dec 04 '25 09:12

Matchu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!