$ _SERVER ['SCRIPT_NAME']与$ _SERVER ['PHP_SELF'](或其他?) [英] $_SERVER['SCRIPT_NAME'] versus $_SERVER['PHP_SELF'] (or other?)

查看:65
本文介绍了$ _SERVER ['SCRIPT_NAME']与$ _SERVER ['PHP_SELF'](或其他?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找一种从pfqpn中提取路径的方法(部分

完全限定路径名)。


$ sThisServer = $ _SERVER ['' HTTP_HOST''];

//返回aquaticcreationsnc.com或 www.aquaticcreationsnc .com


$ sThisServer = $ _SERVER [''SERVER_NAME''];

//返回aquaticcreationsnc.com是否结束 - 用户输入

//在前面的www。


//返回服务器 - 侧映射到文件夹


具体来说,我想要从虚拟主机的根目录到

当前文件夹......到目前为止,我只是得到了这个...


函数GetThisPath(){

return(" http://"。$ _SERVER [''SERVER_NAME'' ] .str_replace(" index.php","",$ _SERVER [''SCRIPT_NAME'']));

}


T hat假设文件夹中的文件名等于index.php。


我可以将它配置为可选参数吗?


函数GetThisPath ($ sFilename =" index.php"){

return(" http://" 。 $ _SERVER [''SERVER_NAME'']。 str_replace(" index.php","",$ _SERVER [''SCRIPT_NAME'']));

}


我''我确定有很多方法可以解决这个问题。我认为

关于implode()/ explode()处理未知文件名,

但是PHP可能已经处理了这个?


主题......是比其他变量更好的变量之一?一个

包装到另一个?哪一个是包装,哪一个是

是最后的调用?谁知道在哪里可以找到这样的细节?如果有

a链接可用...


$ _SERVER [''SCRIPT_NAME'']与$ _SERVER ['''PHP_SELF''] < br $>

非常感谢。


Jim Carlock

发表对小组的回复。

Looking for a way to extract the path from the pfqpn (partially
full qualified path name).

$sThisServer = $_SERVER[''HTTP_HOST''];
// returns either aquaticcreationsnc.com or www.aquaticcreationsnc.com

$sThisServer = $_SERVER[''SERVER_NAME''];
// returns aquaticcreationsnc.com whether or not the end-user typed
// in the preceding www.

$sThisFilePath = getcwd();
// returns server-side mapping to folder

Specifically, I want the path from the root of the virtual host to the
current folder... and so far I''ve got this...

function GetThisPath() {
return("http://" . $_SERVER[''SERVER_NAME''] . str_replace("index.php", "", $_SERVER[''SCRIPT_NAME'']));
}

That assumes the filename in the folder equals "index.php".

I could configure it as an optional parameter?

function GetThisPath($sFilename = "index.php") {
return("http://" . $_SERVER[''SERVER_NAME''] . str_replace("index.php", "", $_SERVER[''SCRIPT_NAME'']));
}

I''m sure there are plenty of ways to handle this. I thought
about implode()/explode() to handle unknown filenames,
but perhaps PHP already handles this?

And the subject... is one of the variables better than the other? One
a wrapper to the other? Which one is the wrapper and which one
is the final calling? Anyone know where to find such details? If there''s
a link available...

$_SERVER[''SCRIPT_NAME''] versus $_SERVER[''PHP_SELF'']

Thanks much.

Jim Carlock
Post replies to the group.

推荐答案

sThisServer =
sThisServer =


_SERVER [''HTTP_HOST''];

//返回aquaticcreationsnc.com或 www.aquaticcreationsnc.com

_SERVER[''HTTP_HOST''];
// returns either aquaticcreationsnc.com or www.aquaticcreationsnc.com


sThisServer =
sThisServer =


这篇关于$ _SERVER ['SCRIPT_NAME']与$ _SERVER ['PHP_SELF'](或其他?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆