php获取当前url路径php服务器变量
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php获取当前url路径php服务器变量,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5883字,纯文字阅读大概需要9分钟。
内容图文
![php获取当前url路径php服务器变量](/upload/InfoBanner/zyjiaocheng/161/097a0aeca77f47429a3ca6d59e9aece5.jpg)
在php编程中编程,获取当前url地址,以及服务器变量,主要使用如下全局变量: $_server["query_string"],$_server["request_uri"],$_server["script_name"],$_server["php_self"] 1,$_server["query_string"] 说明:查询(query)的字符串 2,$_server["request_uri"] 说明:访问此页面所需的uri 3,$_server["script_name"] 说明:包含当前脚本的路径 4,$_server["php_self"] 说明:当前正在执行脚本的文件名 实例: 1,http://bbs.it-home.org/ (直接打开主页) 结果: $_server["query_string"] = "" $_server["request_uri"] = "/" $_server["script_name"] = "/index.php" $_server["php_self"] = "/index.php" 2,http://bbs.it-home.org/?p=222 (附带查询) 结果: $_server["query_string"] = "p=222" $_server["request_uri"] = "/?p=222" $_server["script_name"] = "/index.php" $_server["php_self"] = "/index.php" 3,http://bbs.it-home.org/index.php?p=222&q=biuuu 结果:
例2:
这些变量或函数的异同. 假设有一个请求地址为: http://localhost:8080/test.php/age=20 而test.php 的完整路径是: d:/server/www/example/test.php 1)、getcwd() 将得到浏览器请求的页面文件所在的目录. 即test.php 文件所在的目录: d:/server/www/example/ , 如果在test.php 执行了 require 或 include 语句, 比如 inculde(”test_dir/test2.php”), 那么在 test2.php 里 getcwd()函数 返回的也将是 test.php 所在的目录. 2)、__file__ 一个魔术变量, 用它将得到 __file__ 变量所在文件的完整路径, 比如: test.php 里 __file__ 将得到 d:/server/www/example/test.php , test_dir/test2.php 里的 __file__ 将得到 d:/server/www/example/test_dir/test2.php 3)、$_server["script_filename"] 将得到浏览器请求的页面文件的完整路径. test.php 和 test_dir/test2.php 里用 $_server["script_name"] 都将得到 d:/server/www/example/test.php. 4)、$_server["script_name"] 将得到浏览器请求的页面文件的文件名,注意: 与 $_server["script_name"] 不同, 此变量只得到文件名而不包含路径, 在test.php 与 test_dir/test2.php 用$_server["script_name"] 得到的都将是 test.php. 当然, 在test.php 与 test_dir/test2.php 执行 basename($_server["script_filename"]) 与 $_server["script_name"] 相同. 执行 在test.php 与 test_dir/test2.php 执行 realpath(”test.php”) 得到的结果与 $_server["script_filename"] 相同. 5)、$_server["php_self"] 将得到浏览器请求页面的文件名, 并剥掉问号 ? 后的内容, 注意:不包含路径, 比如在客户端里请求 http://localhost:8080/test.php?age=20&name=tom, 那么test.php 和 test_dir/test2.php 的 $_server["php_self"] 都将得到 “test.php”。“age=20&name=tom”被剥掉。 而如果客户端里请求 http://localhost:8080/test.php/age=20&name=tom, 那么test.php 和 test_dir/test2.php 的 $_server["php_self"] 都将得到 “test.php/age=20&name=tom”。 6)、$_server["request_uri"] 将得到浏览器请求页面的文件名, 以及文件名之后的所有内容(注意: 井号 # 之后的内容将被略去), 比如在客户端里请求 http://localhost:8080/test.php?age=20&name=tom, 那么test.php 和 test_dir/test2.php 的 $_server["reuest_uri"] 都将得到 “test.php”。“age=20&name=tom”被剥掉。 而如果客户端里请求 http://localhost:8080/test.php/age=20&name=tom, 那么test.php 和 test_dir/test2.php 的 $_server["request_uri"] 都将得到 “test.php/age=20&name=tom”。 test.php:
|
内容总结
以上是互联网集市为您收集整理的php获取当前url路径php服务器变量全部内容,希望文章能够帮你解决php获取当前url路径php服务器变量所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。