This can be done by following steps:
- Create a PHP variable which will store the URL in string format.
- Check whether the HTTPS is enabled by the server .If it is, append “https” to the URL string. If HTTPS is not enabled, append “http” to the URL string.( By Using isset() function to check whether HTTPS is enable or not. )
- Append the regular symbol, i.e. “://” to the URL.
- Append the HTTP_HOST(The host to which we have requested, e.g. www.google.com, www.yourdomain.com, etc…) name of the server.
- Append the REQUEST_URI(The resource which we have requested, e.g. /index.php, etc…) to the URL string.
<?php // Program to display complete URL if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') $link = "https"; else $link = "http"; // Here append the common URL // characters. $link .= "://"; // Append the host(domain name, // ip) to the URL. $link .= $_SERVER['HTTP_HOST']; // Append the requested resource // location to the URL $link .= $_SERVER['PHP_SELF']; // Display the link echo $link; ?>
PHP: How to Get the Current Page URL
You may Also Like
By Richard / January 21, 2021
By Richard / January 6, 2021
In Python, there is a module, which allows you to copy a mutable object so that changes made in the...Read More
By Richard / December 15, 2020
What is Unity? According to Wikipedia : Unity is a cross-platform game engine with a built-in IDE developed by Unity...Read More
By Richard / December 1, 2020
Mobile applications have come a long way since the basic arcade game “Snake,” which many consider the first mobile application....Read More
By Richard / November 16, 2020
Information technology is growing rapidly and it is not slowing down, neither it will according to the pace and the...Read More
By Richard / November 6, 2020
Machine Learning is undeniably one of the most influential and powerful technologies in today’s world. Machine Learning is enabling computers...Read More
By Richard / November 2, 2020
A modal is a dialog box/popup window that is displayed on top of the current page: How To Create a...Read More