Home  >  Article  >  php教程  >  php gets the complete URL address of the current page

php gets the complete URL address of the current page

大家讲道理
大家讲道理Original
2016-11-08 17:40:141635browse

<?php
/**
 * 获取当前页面完整URL地址
 */
function get_url() {
    $sys_protocal = isset($_SERVER[&#39;SERVER_PORT&#39;]) && $_SERVER[&#39;SERVER_PORT&#39;] == &#39;443&#39; ? &#39;https://&#39; : &#39;http://&#39;;
    $php_self = $_SERVER[&#39;PHP_SELF&#39;] ? $_SERVER[&#39;PHP_SELF&#39;] : $_SERVER[&#39;SCRIPT_NAME&#39;];
    $path_info = isset($_SERVER[&#39;PATH_INFO&#39;]) ? $_SERVER[&#39;PATH_INFO&#39;] : &#39;&#39;;
    $relate_url = isset($_SERVER[&#39;REQUEST_URI&#39;]) ? $_SERVER[&#39;REQUEST_URI&#39;] : $php_self.(isset($_SERVER[&#39;QUERY_STRING&#39;]) ? &#39;?&#39;.$_SERVER[&#39;QUERY_STRING&#39;] : $path_info);
    return $sys_protocal.(isset($_SERVER[&#39;HTTP_HOST&#39;]) ? $_SERVER[&#39;HTTP_HOST&#39;] : &#39;&#39;).$relate_url;
}
 
echo get_url();
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn