Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Created October 4, 2014 09:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bappi-d-great/bc4037a4896f0dd233e6 to your computer and use it in GitHub Desktop.
Save bappi-d-great/bc4037a4896f0dd233e6 to your computer and use it in GitHub Desktop.
Get current page url in php
<?php
function current_page_url() {
$url = 'http';
if ($_SERVER["HTTPS"] == "on")
$url .= "s";
$url .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
$url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
return $url;
}
// Now use the function like following:
$url = current_page_url();
//or
echo current_page_url();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment