How do I capture the whole URL using PHP?

2020-03-30 15:39发布

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.

标签: html php url
2条回答
淡お忘
2楼-- · 2020-03-30 16:05

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

查看更多
仙女界的扛把子
3楼-- · 2020-03-30 16:09

like this one..

$(function() {
$('.ajax-link').click( function() {
var link=$(this).attr('href');
     $.post( "savedl.php",{name:link}, 
     function(data) {
        window.location.href=link;
     });
     return false; // don't follow the link!

  });
});

sample is i have the url in the link

<a href='' class="ajax-link" id="url_name">url </a>

then you can get the value on savedl.php using $_POST['name']

查看更多
登录 后发表回答