Posted By

rickygri on 12/18/12


Tagged

php server windows apache IIS root


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

daK76


Get current URL with PHP in Apache or IIS


 / Published in: PHP
 

URL: http://dev.kanngard.net/Permalinks/ID_20050507183447.html

Get Current URL Path on Apache / IIS

  1. // On Apache ->
  2.  
  3. function selfURL() {
  4. $s = empty($_SERVER["HTTPS"]) ? ''
  5. : ($_SERVER["HTTPS"] == "on") ? "s"
  6. : "";
  7. $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
  8. $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
  9. : (":".$_SERVER["SERVER_PORT"]);
  10. return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
  11. }
  12. function strleft($s1, $s2) {
  13. return substr($s1, 0, strpos($s1, $s2));
  14. }
  15.  
  16. // On IIS ->
  17.  
  18. function selfURL(){
  19. if(!isset($_SERVER['REQUEST_URI'])){
  20. $serverrequri = $_SERVER['PHP_SELF'];
  21. }else{
  22. $serverrequri = $_SERVER['REQUEST_URI'];
  23. }
  24. $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
  25. $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
  26. $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
  27. return $protocol."://".$_SERVER['SERVER_NAME'].$port.$serverrequri;
  28. }
  29.  
  30. // Get Current URL ->
  31.  
  32. print(selfURL());

Report this snippet  

You need to login to post a comment.