2

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!

4

1 に答える 1

2

いいえ、これは不可能です。

サービス対象のドメインの docroot にあるファイルを指定する Web サーバー構成への PHP ファイル内からの参照はありません。作成された 1 つの要求に対して、すべて$_SERVERの変数が Web サーバーから PHP に渡されます。ファイルをインクルードすることは、実行するためにそれらをインクルードするだけです。つまり、ファイルは最初のリクエストのコンテキストで実行されます。

于 2012-05-06T18:23:43.443 に答える