You can get the URL of currently loaded page you’re in, follow the steps below;
- You will need to copy the function codes below;
<?php
$url = get_url();
function get_url () {
if (isset($_SERVER['REQUEST_URI'])) {
$url = $_SERVER['REQUEST_URI'];
} else {
$url = $_SERVER['SCRIPT_NAME'];
$url .= (!empty($_SERVER['QUERY_STRING'])) ? '?' . $_SERVER['QUERY_STRING'] : '';
}
return $url;
}
?>
- Paste them to a blank notepad, and then save the file as get-url.php
- Upload the file get-url.php on your server.
- In order to retrieve the URL captured by the function, first you will need to include the get-url.php file to wherever you want the URL to be captured;
<?php include (”get-url.php”) ?>
- You can retrieve the captured URL via using this piece of code;
<?php echo $url?>
- Here’s the output of the captured URL for this page;
/tutorial/php/get-url/
Comment?
»
Leave a comment
ajwa . Naj . Wawa . 26 . 











