Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find where PHP Javascript is called from?

Status
Not open for further replies.

LeonKl2

Programmer
Jun 16, 2003
26
US
I am using a PHP page to generate JavaScript code so that the result can be called with a < script src tag.

How can I find out what sites this Javascript request is coming from? The regular refferer variables don't seem to work.

It should be possible to do this.

Thanks,
Leon
 
Perhaps someone else can help directly from what you've offered, but I'm a bit unclear... you're using PHP to generate javascript code, then you're including this in another page using a
Code:
<script src=&quot;somepagewhichgeneratesjavasource.php&quot;></script>
tag?

Then you're trying to figure out the name of the page with the above tag in it? And which referrer variables aren't working?

Now perhaps I've come to understand you by what I just typed... if so, then all you should need is $_SERVER['HTTP_REFERER']

In fact, I just made these two pages...

Code:
test.html
<html>

<head>
<script src=&quot;testjs.php&quot;></script>
</head>

<input type=&quot;button&quot; onclick=blah() />
</html> 

AND
testjs.php
<?php
echo '
function blah() {
  alert(&quot;'.$_SERVER['HTTP_REFERER'].'&quot;);
}
';
?>

And when I click on the button, I get
Or did I miss the question afterall?

Hope it helps...
Rob
 
Users can turn their browsers referrer reporting off. So, there is no deterministic way of telling where the request came from. The user's IP also has not much to say, since proxy servers etc. can alter the real value.

Since you are generating the JavaScript you should include a parameter that is also generated on the fly, unique and reports back to you.

Have the people that use your JS sign up and give them an ID. These are just a few ideas...
 
Rob,

You got my idea exactly. And I could have sworn $_SERVER['HTTP_REFERER'] should work. I tried it but it didn't.

I think that this is because my firewall is blocking the referer from my browser.

Maybe I'll try it out again and see if I can turn it off.

Thanks,
Leon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top