views:

41

answers:

1

I have an embed script that simply does this:

document.write(unescape('%3Cscript src="' + mp_protocol + 'blah.cloudapp.net/js?location="' + window.location +' type="text/javascript"%3E%3C/script%3E'));

As you can see right now the URL of the webpage that is embedding the code is passed in using window.location. But this can easily be edited by the client.

I wanted to know if I can get the referrer instead of passing the url. I wasn't sure if referring info would be passed since this script is embedded?

(yes, you can also fake referrers... but that is a bit more effort than I think most people will want).

+2  A: 

The browser will usually send a "Referer" (sic) header for script requests which contain the URL of the page that containing the script link, regardless of how that script element was created.

This is accessible by checking the "Referer" HTTP variable (note unusual spelling).

The idea is that you can check this variable and see if it refers to part of your site.

Note that this variable is not always accurate; a user may elect to protect their privacy by not sending a referer header (using some sort of dinky privacy tool) and they may even modify their browser to send whatever they want in this field. So it shouldn't be relied upon for authentication, unless you also take into account that even a legitimate user may have left it blank or put an arbitrary string in it.

thomasrutter
the OP is not on php.
Reigel
oh yeah, you're right!
thomasrutter