7three
7three

Reputation: 344

Is it possible to get the domain name of the script included by a script of a folder with a other domain?

An example for my question:

I've a script in the document root (htdocs or what ever) for the domain (as example) "root.co.uk", where I want to generate a link to the "file" domain:

/htdocs/include.file.php

<?php
  echo $_SERVER['HTTP_HOST']; // another.com -> but I like to have "root.co.uk" here :(
?>

And now I've a subfolder for the domain (as example) "another.com", which will be loaded via browser:

/htdocs/another.com/index.php -> http://www.another.com

<?php
  include('/htdocs/include.file.php'); // Include file from "root.co.uk"
?>

Is there any way to pass the domain name? The only solution, as far as I see, is to define a var like $maindomain = 'root.co.uk'. But thats not the way I like to do it. :(

Thanks for any ideas!

Upvotes: 2

Views: 555

Answers (1)

Brad
Brad

Reputation: 163438

No, this isn't possible.

There is no reference from within your PHP files to the web server configuration that specifies what files are in the docroot for the domains being served. Any $_SERVER variables are passed to PHP from the web server for the one request that was made. Including files does nothing more than include them to execute, which means they will run in the context of the initial request.

Upvotes: 2

Related Questions