0

Server (website) 1 using this code:

<script type="text/javascript" src="http://server2.tld/script.php"></script>

on server 2 I would now like to get the domain name of the requesting server 1.

Is that possible?

webGuy
  • 121
  • 2
  • 9
  • 1
    You might get the IP, not necessarily the domain name. Check the request headers in `$_SERVER` from server2 – scrowler Oct 05 '18 at 15:08
  • I already checked get_defined_vars () and did not find a domain. – webGuy Oct 05 '18 at 15:15
  • You'll need to look in `$_SERVER`, either `$_SERVER['REMOTE_ADDR']` for the IP or maybe `$_SERVER['REMOTE_HOST']` for the domain - I'm not sure whether it will resolve though, but worth a shot – scrowler Oct 05 '18 at 15:16

2 Answers2

0

You can pass the url in the path to open server 2.

Server 1:

href=“server1.php?url='http://server2.tld/script.php'“

Anywhere in your server 1 code, you have a href to open server 2. Replace the href with the code at the top.

In your server 2, you have to get this code with this simple line:

$url = $_GET['url'];
Jakob
  • 1,448
  • 2
  • 10
  • 22
  • I need to check if the requesting server (domain) is allowed to access my script on server 2 or not. That said it is unfortunately not an option to pass the url. – webGuy Oct 05 '18 at 15:25
0

So i have 2 valid options.

First Option

You could try

$referer = parse_url($_SERVER['HTTP_REFERER']);
$referer = $referer['host'];

but this is option only available if set by the client, so i might not be available.

Second Option

would be to create an api, and post the reference url via curl... technically its not the requested who figures out the ulr but the requester how send its... but this stackoverflow post should help you...

PHP + curl, HTTP POST sample code?

i hope this answers the question... if you have further questions pleas ask.