1

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.

A Star
  • 605
  • 9
  • 18

2 Answers2

4

try this function

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

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

taken from [this article I wrote][1]

use it like

echo getURL();

see if works for you [1]: http://jaspreetchahal.org/how-do-you-get-current-browser-url-with-php/

cigien
  • 57,834
  • 11
  • 73
  • 112
Jaspreet Chahal
  • 2,759
  • 1
  • 15
  • 17
0

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']

Bert
  • 1,019
  • 3
  • 14
  • 25