You cannot "guess" this information from your show_widget.php
script : clientsite will have to transmit that information to your script.
Which means your widget should be included with some code like this (provided the page on clientsite is generated in PHP) :
<script
type="text/javascript"
src="http://widgetserver.com/show_widget.php?referer=<?php echo urlencode($_SERVER['HTTP_REFERER']); ?>>
</script>
Of course :
- don't forget to escape the referer while injecting it into the page, for security (and to get valid-HTML)
- the referer might not always be present : it is sent by the user's browser, and can be both faked and/or disabled.
To avoid a "Notice: Undefined index: HTTP_REFERER" from being generated/displayed when there is no referer sent by the user's browser, you might also want to add a check, to find out if it's defined before using it -- use isset
for that ; for instance, something like this might do :
<script
type="text/javascript"
src="http://widgetserver.com/show_widget.php?referer=<?php echo isset($_SERVER['HTTP_REFERER']) ? urlencode($_SERVER['HTTP_REFERER']) : ''; ?>>
</script>