<?php // 说明:获取完整URL 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; } ?> 定义该函数之后就可以直接调用了:
<?php // 说明:获取无参数URL function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; $this_page = $_SERVER["REQUEST_URI"]; // 只取 ? 前面的内容 if (strpos($this_page, "?") !== false) $this_page = reset(explode("?", $this_page)); if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $this_page; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $this_page; } return $pageURL; } ?>
<?php // 说明:获取无参数URL 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 // 说明:获取 _SERVER['REQUEST_URI'] 值的通用解决方案 // 来源:drupal-5.1 bootstrap.inc // 整理:http://www.php.cn/ function request_uri() { if (isset($_SERVER['REQUEST_URI'])) { $uri = $_SERVER['REQUEST_URI']; } else { if (isset($_SERVER['argv'])) { $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0]; } else { $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING']; } } return $uri; } ?>