Forum Moderators: open

Message Too Old, No Replies

HTTP_REFERER missing when navigation using Javascript

Probably as much browser-related as PHP-related

         

Lymeswold

10:34 am on Oct 8, 2003 (gmt 0)

10+ Year Member



Suspect this is as much a browser/ecmascript question as PHP... (I don't want to cross-post)

I have a page with navigation to another page either via either

a clickable href link

or..

a script which reads the keyboard, looking for a specific key sequence

The script does this via document.location("whatever").

Navigation works fine in both cases, but in the target page I need to find where the browser has come from. $_SERVER['HTTP_REFERER'] is set when arriving via the clickable link, but is blank when arriving via the script.

This looks to be browser behaviour. Is there any way to get the referrer in the latter case using the REFERER header mechanism (yes, I know it's not completely reliable cross-browser!)?

Thanks,

Chris

jatar_k

4:47 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



interesting behaviour, I don't know if it is the browser or javascript itself.

I very seldom use js links so I haven't run into this.

Anyone?

DrDoc

4:51 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's JavaScript related... Has nothing to do with PHP :)

Are you opening the page in a new window or not?

RonPK

5:06 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In general, one should not rely too much on the referrer string, since it can be empty because of firewall and privacy settings.

DrDoc

5:46 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...or simply spoofed

dmorison

6:01 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Standard behaviour for JavaScript.

Lymeswold

7:22 pm on Oct 8, 2003 (gmt 0)

10+ Year Member



I checked whether the referrer was available from Javascript - document.referrer - and it wasn't. So this is clearly the browser.

My best guess is that Javascript doesn't allow this because of possible cross-domain or cross-page security issues.

Anyway I've worked out how to get the same effect using cookies.

Chris