1

I have a file on my site and many external sites are importing this file on their websites with the file_get_contents php code.

Is it somehow possible with PHP to get the URL of these external sites accessing my file? Something like: if siteX accesses my page Y, add siteX URL to sites.txt

10now
  • 387
  • 2
  • 3
  • 14
  • You can get the IP of the webserver, you can't get the name of the page. You may be able to use reverse DNS to translate the IP to a hostname, but if they're using shared hosting that won't tell you the specific name of the server that's accessing your file. – Barmar Dec 11 '14 at 11:09

3 Answers3

3

If you have access to your server: simply parse the access.log.

If you don't have access to the server, then you might try to determine the Client IP via $_SERVER.

$visitors_ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR');

More here: How to get the client IP address in PHP?

Boils down to: on each request, determine visitor ip and store to your file.

Community
  • 1
  • 1
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
1

No, it's not possible, unless all the sites are yours. You can't know what is in other people's PHP code.

You might track the IP addresses, probably, but it'll be tedious and unreliable task.

Are you sure this is really what you want? Wouldn't it be better to use some kind of redirection instead?

MightyPork
  • 18,270
  • 10
  • 79
  • 133
0

Well, you can log the referral header from Apache for every request, if you can configure apache on your site.

Here you can find an example of how to achieve this:

http://simonecarletti.com/blog/2009/01/logging-external-referers-with-apache/

Juan de Parras
  • 768
  • 4
  • 18