You can use PHP $SERVER variable for getting current page URL. Being super global variable you will get access to $SERVER in any part of PHP application.
Below is a sample script getting the URL of the current page in PHP
<?php $uripart = $_SERVER['REQUEST_URI']; $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; //If there are query string $query = $_SERVER['QUERY_STRING']; $url = $url.'?'.$query; ?>
You may find these articles helpful:
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply