Tuesday 3 June 2014

How to get current full URL in PHP 0

To get current full url in php, we can use php's $_SERVER variables.

We are going to use
  • $_SERVER[REQUEST_SCHEME]  - It will print which type scheme (ex.http)
  • $_SERVER[HTTP_HOST]       -  Server host name
  • $_SERVER[REQUEST_URI]      - current URI 
So, We can combine those three like below,
$URL = $_SERVER[REQUEST_SCHEME].'://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
 Simply echo it like this echo $_URL; to test it.

Have any doubt, feel free to comment here!

Related Post : How to get full referrer url in php

0 comments:

Post a Comment