Get the url of current page using PHP


It often appears that you need to get the current page url in some kind of CMS or on PHP. The code below lists the details of how easy it is to get the full URL.

<?
	if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) #Get the site protocol.
		$protocol="https://";
	else
		$protocol="http://";

	$domain=$_SERVER['SERVER_NAME']; #Get current domain.

	$currentUrl=$_SERVER['REQUEST_URI']; #Get current page link with parameters.

	#As a result, we get the code that gives us the current page url.
	$url=$protocol.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
	
	#And separately you can get the parameters passed to the page separately.
	$query=$_SERVER['QUERY_STRING']; 
?>



Connect

If you have any questions, want to get individual advice or you have an interesting offer, you can contact via the feedback form.

Or write to the email info@bobreod.ru





By submitting the form, you agree to our privacy policy