Get the current url in PHP

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();
Tags: ,

Related posts:

HTML5 page structure

HTML5 offers more powerful structure comparing to older versions of Html. There are many new …

Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us