获取当前页面的url地址php教程代码,第一款是一款获取无参数url,第二款是获取完整url函数.
方法一:
- <?php
-
- function curpageurl()
- {
- $pageurl = 'http';
- if ($_server["https教程"] == "on")
- {
- $pageurl .= "s";
- }
- $pageurl .= "://";
- if ($_server["server_port"] != "80")
- {
- $pageurl .= $_server["server_name"].":" . $_server["server_port"] . $_server['php_self'];
- }
- else
- {
- $pageurl .= $_server["server_name"] . $_server['php_self'];
- }
- return $pageurl;
- }
- ?>
方法二
- <?php
-
- function curpageurl()
- {
- $pageurl = 'http';
- if ($_server["https"] == "on")
- {
- $pageurl .= "s";
- }
- $pageurl .= "://";
- if ($_server["server_port"] != "80")
- {
- $pageurl .= $_server["server_name"] . ":" . $_server["server_port"] . $_server["request_uri"];
- }
- else
- {
- $pageurl .= $_server["server_name"] . $_server["request_uri"];
- }
- return $pageurl;
- }
- ?>
另外,$_server['request_uri'] 和 $_server['request_url'] 是有稍微区别的:
$_server["request_uri"] 返回完整的路径(/directory/file.ext?query=string)
$_server['request_url'] 只返回文件路径,不包括参数,(/directory/file.ext),和$_server['php_self']差不多,只不过在有些服务器上$_server['request_url']不可用.