PHP 站点根 url

发布于 2024-10-08 05:12:04 字数 430 浏览 0 评论 0原文

我正在通过贝宝进行付款,使用将商品详细信息提交给贝宝。 这里我需要指定我的notify.php的链接。 为此,我需要动态获取我的网站根目录。 我怎样才能得到它。

我的系统文件夹结构是 C:\wamp\www\website\store_esp\notify.php

和我的 notification.php 的 url 应该是 http://domainname/store_esp/notify.php

目前我的域名是 http://localhost/website/

如何使用 php.ini 动态获取域名?

I am doing a payment by paypal using submit the item details to paypal.
Here I need to specify a link of my notify.php.
For this I need to get my site root dynamically.
how can I get it.

my system folder structure is
C:\wamp\www\website\store_esp\notify.php

and my url for notify.php should be
http://domainname/store_esp/notify.php

Presently my domail name is http://localhost/website/

How can I get the domainname dynamically using php.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

‘画卷フ 2024-10-15 05:12:05

该 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.html 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/a/36101073/3626097

This PHP function returns the real URL of a full path.

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;
}

Call of pathUrl in this file : http://example.com/shop/index.php

#index.php

echo pathUrl();
//http://example.com/shop/

Work with alias : http://example.com/alias-name/shop/index.php

#index.php

echo pathUrl();
//http://example.com/alias-name/shop/

For sub directory : http://example.com/alias-name/shop/inc/config.php

#config.php

echo pathUrl(__DIR__ . '/../');
//http://example.com/alias-name/shop/

https://stackoverflow.com/a/36101073/3626097

醉南桥 2024-10-15 05:12:04

$_SERVER['HTTP_HOST'] 将给出域名

 http://localhost/website

在上面的 URL 中,域是 localhost
我认为 website 永远不会更改为 website1website2,因此您可以在网址中静态提及这一点。

$_SERVER['HTTP_HOST'] will give the domain name

 http://localhost/website

In the above URL the domain is localhost
As I think the website is never changed to website1 or website2 so you can statically mention this in your url.

屋顶上的小猫咪 2024-10-15 05:12:04

使用这个

http://".$_SERVER['HTTP_HOST']."/store_esp/

,然后使用像notify.php这样的文件名

use this

http://".$_SERVER['HTTP_HOST']."/store_esp/

and after this use the filename like notify.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文