如何使用PHP捕获整个URL? [英] How do I capture the whole URL using PHP?

查看:65
本文介绍了如何使用PHP捕获整个URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要整个URL,包括_GET变量名称和值,例如www.mywebsite.com/store.php?department=MENS

我在下面使用的代码仅提供了不含_GET变量部分的URL.

$url = $_SERVER['SERVER_NAME']; 
$page = $_SERVER['PHP_SELF'];
$page = $_POST['url'];
echo "http://".$url.$page; 

我只想能够完全复制该URL.

解决方案

尝试此功能

  public function getURL()
     {
        $protocol = @$_SERVER['HTTPS'] == 'on' ? 'https' : 'http';

        return  $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
     }

摘录自 hre

喜欢使用

echo getURL();

看看是否适合您

I would like to the whole of the URL including the _GET variable names and values, for example www.mywebsite.com/store.php?department=MENS

The code I have used below only gives me the URL without the _GET variable part.

$url = $_SERVER['SERVER_NAME']; 
$page = $_SERVER['PHP_SELF'];
$page = $_POST['url'];
echo "http://".$url.$page; 

All I would like is to be able to copy that URL exactly how it is.

解决方案

try this function

  public function getURL()
     {
        $protocol = @$_SERVER['HTTPS'] == 'on' ? 'https' : 'http';

        return  $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
     }

taken from hre

use it like

echo getURL();

see if works for you

这篇关于如何使用PHP捕获整个URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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