tags:

views:

410

answers:

5

I know how to find out the current domain name in PHP already, the problem is when I put this code into a file and then include it from another server it shows the domain name of where the file is located. Is there any way for it to find out the domain or the site containing the include() code?

A: 

If you include a PHP page from another server, the page will get parsed by the original server and the result will be sent to you - the page you receive is nothing but text, no PHP code included.

Christian P.
I kinda figured that out by this point, hence my problem. Is there no possible way of doing this?
zuk1
why are you including a file hosted on another server? What problem are you trying to solve?
MDCore
I own large networks of site and I am writing a script which will help manage them.
zuk1
You might want to look into something like Nagios rather than cobbling together a management platform.
Mitch Haile
A: 

This is a crude hack, but on the remote server, you could look up the domain name of $_ENV['REMOTE_HOST'].

This would be the domain name of the guy doing the "include" from the perspective of the remote server.

I assume you have some reason for wanting to implement this strange topology--restrictions in a virtual host environment, or something. I would suggest looking into alternative infrastructure if possible.

Mitch Haile
+1  A: 

Are you doing something like:

include 'http://example.com/script.php';

?

NB: This approach generally considered to be a bit of no-no from a security point of view.

Anyway, the included script is actually being executed on the other server, then the output of the script is being executed on the current server. You can get around this by echoing actual code, something like this:

Currently:

<? 
//do something
echo '$v = '.$_SERVER['HTTP_HOST'].';'
?>

Other way:

<?
//do something
?>
$v = $_SERVER['HTTP_HOST'];

But then maybe I'm misunderstanding your question.

J.D. Fitz.Gerald
A: 

You can run it locally using "eval" then it should use the proper domain store your script as a text file then download it and then execute:

eval(file_get_contents("http://someDomain.com/somePhpscript.txt"));
SeanDowney
A: 

if you're calling a script on a remote site, won't you already know the domain name?

nickf