How to get the full URL in PHP
To Get Full URL in PHP:
In this post, We are discussing about How to get the full URL in PHP.
Table Of Content
Have a look at:
[ad type=”banner”]Note: That the double quoted string syntax is perfectly correct
- If we want to support both HTTP and HTTPS, we can use
- Using this code has security implications. The client can set HTTP_HOST and REQUEST_URI to any arbitrary value
- Using a ternary statement:
- Cross platform method for finding the current URL is:
Sample code:
- It works for all webservers (Apache, nginx, IIS, …):
- we can get full current URL including $_SERVER[‘REQUEST_URI’].
Function:
[ad type=”banner”]Test code:
- Function to handle the URL:
- HTTPS support:
Code:
- Here is the another way of solution:
- You can use this code:
- $_SERVER is an array containing information such as headers, paths, and script locations.
- The entries in this array are created by the web server.
- $HTTP_SERVER_VARS contains the same initial information, but is not a superglobal. (Note that $HTTP_SERVER_VARS and $_SERVER are different variables.)
