Home > php教程 > PHP源码 > php gets the complete URL address of the current page

php gets the complete URL address of the current page

大家讲道理
Release: 2016-11-08 17:40:14
Original
1721 people have browsed it

<?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();
?>
Copy after login

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template