Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting current URL

Tags:

I am using following code to get the current URL

$current_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 

Is there any other way to get the same, or may be better way to get current URL?

Thanks.

like image 940
I-M-JM Avatar asked Mar 07 '11 05:03

I-M-JM


1 Answers

From the reference:

<?php  function curPageURL() {     $pageURL = 'http';      if ($_SERVER["HTTPS"] == "on") {         $pageURL .= "s";     }     $pageURL .= "://";      if ($_SERVER["SERVER_PORT"] != "80") {         $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];     } else {         $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];     }      return $pageURL; } ?> 
like image 107
diEcho Avatar answered Nov 09 '22 21:11

diEcho