获取当前页面的完整URL(PHP) [英] Getting the full URL of the current page (PHP)

查看:185
本文介绍了获取当前页面的完整URL(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在此页面上:http://localhost/projectname/custom.php

<?php echo $_SERVER['REQUEST_URI']; ?><?php echo $PHP_SELF; ?>均未提供完整位置.我应该使用什么来获取完整的URL位置?

Both <?php echo $_SERVER['REQUEST_URI']; ?> and <?php echo $PHP_SELF; ?> don't give full location. What should I use to grab the full url location?

推荐答案

function selfURL() 
{ 
    $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; 
    $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
    $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
    return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; 
} 

function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }

这篇关于获取当前页面的完整URL(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆