GET URL in Adress Bar without params

Hello
I want to get url in adress bar without params
the problem that the server url is different from the one shown in adress bar but I want to show the one in adress bar not real url

Some of my tries

function getAddress() {
    $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
    return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}

echo getAddress();

The alternative in jquery is

$(location).attr('href');
  • I want the url without params

Thanks in advance

Well keep in mind that PHP runs at the server end, before anything is sent to the browser. So it has no concept of “address bar”.

What mechanism are you using to change ‘the server url’ to the one ‘shown in adress bar’?

1 Like

Try the following which should show all the parameters passed, select the relevant parameter and perhaps use PHP string functions to extract the required data:

echo '<pre>'; // add line feed so it is easier to read.
   print_r(  $_SERVER );
echo '</pre>';
die; // halt execution

I have found the solution

		$(document).ready(function(){
				//
		var xlocation = location.protocol+'//'+location.host+location.pathname;
		console.log(xlocation);
		$("head").prepend("<link rel='canonical' href='"+xlocation+"'>")
		//	
		})

but I need to convert it to PHP
Thanks in advance

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.