我正在做贝宝付款使用提交的项目细节贝宝。在这里我需要指定我的notify.php的链接。为此,我需要动态获取我的站点根目录。我怎么才能得到它。
我的系统文件夹结构是C:\wamp\www\website\store_esp\notify.php
我的notify.php的url应该是http://domainname/store_esp/notify.php
目前我的域名是http://localhost/website/
如何使用php动态获取域名。
发布于 2010-12-18 15:16:14
$_SERVER['HTTP_HOST']会给出域名
http://localhost/website在上面的网址中,域名是localhost,因为我认为website永远不会更改为website1或website2,所以你可以在网址中静态地提到这一点。
发布于 2010-12-18 15:19:38
使用这个
http://".$_SERVER['HTTP_HOST']."/store_esp/然后使用像notify.php这样的文件名
发布于 2016-03-19 19:37:54
此PHP函数返回完整路径的实际URL。
function pathUrl($dir = __DIR__){
$root = "";
$dir = str_replace('\\', '/', realpath($dir));
//HTTPS or HTTP
$root .= !empty($_SERVER['HTTPS']) ? 'https' : 'http';
//HOST
$root .= '://' . $_SERVER['HTTP_HOST'];
//ALIAS
if(!empty($_SERVER['CONTEXT_PREFIX'])) {
$root .= $_SERVER['CONTEXT_PREFIX'];
$root .= substr($dir, strlen($_SERVER[ 'CONTEXT_DOCUMENT_ROOT' ]));
} else {
$root .= substr($dir, strlen($_SERVER[ 'DOCUMENT_ROOT' ]));
}
$root .= '/';
return $root;
}此文件中的pathUrl调用:http://example.com/shop/index.php
#index.php
echo pathUrl();
//http://example.com/shop/使用别名:http://example.com/alias-name/shop/index.php
#index.php
echo pathUrl();
//http://example.com/alias-name/shop/子目录:http://example.com/alias-name/shop/inc/config.php
#config.php
echo pathUrl(__DIR__ . '/../');
//http://example.com/alias-name/shop/https://stackoverflow.com/questions/4477086
复制相似问题