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 […]