且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

尝试在PHP中获取不带文件名的完整URL

更新时间:2023-02-25 14:13:18

不会有一个,因为它不是要跟踪的有用属性.如果当前脚本不是index.*以外的其他内容,则不会返回当前脚本的正确URL.

There won't be one because it's not a useful attribute to track. If the current script is something other than index.* then it will not return the correct URL for the current script.

但是,这可能会给您带来想要的东西:

However, this might get you what you want:

echo '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);


另外,除了安装Firefox的php.net在线手动搜索工具并使用搜索关键字进行设置(通过在URL中键入"php $_server"之类的字词,您可以在$_SERVER全局文档中找到文档)栏),您还应该知道var_dump()print_r()可以让您输出任何变量的完整内容,包括数组和对象.这对于调试非常有用.


Also, aside from installing the php.net online manual search tool for Firefox and setting it up with a search keyword (which will let you pull up the documentation on the $_SERVER global by typing something like "php $_server" into your URL bar), you should also know that var_dump() and print_r() lets you output the full contents of any variable, including arrays and objects. This is very useful for debugging.