The following string variable’s value will get the full URL of the current page, including GET arguments/params, if present.
1 2 3 4 5 6 |
<?php $full_current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; echo $full_current_url; ?> |
To get the full URL of current page but WITHOUT the GET args/params, do this instead:
1 2 3 4 5 6 |
<?php $full_current_url = "http://" . strtok($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], "?"); echo $full_current_url; ?> |
The strtok
function will return only the part of the URL string up to the character before question mark “?” which is used by GET args/params.
strtok
was suggested in this StackOverflow answer: http://stackoverflow.com/a/4643312