您好,欢迎访问一九零五行业门户网

php $

$_server[ request_uri ]只在支持path_info的web服务器中可用 具体对php来讲就是apache下可用,php5中可用 另外$_server只在php4.1.0以上可用 $_server[request_uri]函数 预定义服务器变量的一种,所有$_server开头的都叫做预定义服务器变量 request_uri的作
$_server[ request_uri ]只在支持path_info的web服务器中可用 
具体对php来讲就是apache下可用,php5中可用
另外$_server只在php4.1.0以上可用
$_server[request_uri]函数
预定义服务器变量的一种,所有$_server开头的都叫做预定义服务器变量 request_uri的作用是取得当前uri,也就是除域名外后面的完整的地址路径
例如。当前页面是http://www.zixueku.com/plus/search.php?kwtype=0&keyword=php&searchtype=titlekeyword
echo $_server[request_uri];
结果就为:plus/search.php?kwtype=0&keyword=php&searchtype=titlekeyword
假如命令行的地址是:http://www.baidu.com/index.php那么:$_server['http_host']=='www.baidu.com'$_server['php_self']=='/index.php'明白了吧,一个是主机地址,一个是脚本文件的绝对路径
“php_self” 
当前正在执行脚本的文件名,与 document root 相关。举例来说,在 url 地址为 http://www.jb51.net/test.php/foo.bar 的脚本中使用 $_server['php_self'] 将会得到 /test.php/foo.bar 这个结果。__file__ 常量包含当前(例如包含)文件的绝对路径和文件名。
“script_name” 
包含当前脚本的路径。这在页面需要指向自己时非常有用。__file__ 包含当前文件的绝对路径和文件名(例如包含文件)。
主要的原因如像:$_server['php_self'] ? $_server['php_self'] : $_server['script_name'];
找到更好的原因是: 
今天在dreamhost上安裝一套php程序時發現連接的地址都會多出一個cgi-system來,但是程序的config並沒有問題,查了查資料才發現是script_name和php_self不同造成的問題。 
通常在本機測試 $_server['script_name'] 跟 $_server['php_self'] 大概看不出有什麼不同,因為大部分的php不是以cgi模式運行的。 
但 dreamhost 上的 php 是以 cgi 方式運行,二者就有明顯不同的差異。 
echo $_server['script_name']; // (/cgi-system/php.cgi) 
echo $_server['php_self']; // (/admin/test.php)
从http://lists.nyphp.org/pipermail/talk/2005-july/015339.html 发现了一个说明。老外说的。
script_name solves all the problems mentioned 
in this thread - it's just the script name, without any extra garbage 
that might be tacked on by the user. php_self explicitly includes that 
extra garbage, so solutions in this thread that involve stripping the 
garbage off of php_self to make it safe are really, really missing the 
point - just use script_name instead. please don't use form action=”; 
according to the spec, what the browser does with that is undefined, so 
even if it works in current browsers, it might not work in future ones
其它类似信息

推荐信息