This seems like it should be simple. Any pointers would be much appreciated.
Consider three sites:
- widgetserver.com, which serves widgets to client sites
- clientsite.com, which displays the widget
- previoussite.com, which is a site that links to clientsite.com
In clientsite.com’s page there is a piece of code that calls a PHP function on widgetserver.com. It looks like this:
<script type="text/javascript" src="http://widgetserver.com/show_widget.php></script>
When clientsite.com is loaded, it runs “show_widget.php”, which in turn places the widget on the page.
This is where I am stuck: I would like to access the site that referred the user to clientsite.com from inside “show_widget.php”, but while in this function we are on widgetserver.com, so the referrer is clientsite.com, not previoussite.com.
Is there any way I can pass clientsite.com’s referrer to “show_widget.php”?
document.referrer contains the referrer information you want, so if they’re running javascript, you could do something like this:
This will need to go OUTSIDE of the head tag (unless it’s in a function being bound to the document ready event or something), or it will fail.
The idea behind this is to generate a dynamic tag on the page with the attributes you want. The first line creates it, second line sets the script src, and the third page loads it into the document.head DOM element, which causes it to be evaluated, and loads the document as required.
If your clients are using jQuery, it is easier to use $.getScript, with a similar use of document.referrer