Home » Labs » Get the current url in PHP  

Get the current url in PHP

Filed under Labs

If you are a web developer then some times you need to get the current page URl. Here is a simple to get current url of a web page using php.

PHP function

// the following function will return current page url
function cPageURL()
	$pageURL = 'http';
	if ($_SERVER['HTTPS'] == 'on'){
		$pageURL .= 's';
	$pageURL .= '://';
	if ($_SERVER['SERVER_PORT'] != '80'){
	return $pageURL;

Call the function

You can now get the current page URL by calling the above function like following.

  echo cPageURL();

Posts you may like: