Question

I know you can get the HTTP referer when someone enters your page by clicking a link to it. But is it also possible to determine what page a user is on when they type the address themselves?

Was it helpful?

Solution

According to the standard, the browser MUST NOT send the address of the current page when an address is entered by the user. From the HTTP/1.1 header field documentation:

The Referer field MUST NOT be sent if the Request-URI was obtained from a source that does not have its own URI, such as input from the user keyboard.


Below is my previous answer, which didn't exactly match the question, but I've left it here for history purposes.

The referrer would be empty (or non-existent) if the address is typed directly into the browser, but that's not really something you can rely on (i.e. the referrer could be empty for other reasons).

One notable reason for the referrer to be empty is when a browser switches from secure to non-secure mode.

OTHER TIPS

There might be some obscure browser that sends whatever URL the user was on as HTTP REFERER when he/she typed your URL (or clicked a bookmark), but generally no.

Its not possible to get referrer directly from keyboard

If Its the same domain & system you can use Permanent Cookies as a simple workaround

Example

   setcookie("lastLink"  ,$value, mktime (0, 0, 0, 12, 31, 2020));

Anytime the user comes back you can retrieve the last link $_COOKIE['lastLink']

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top