Get the full URL of current document


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Returns the full URL of the current document.
  2. function getCurrentUrl()
  3. {
  4. // Checks scheme.
  5. $url = ($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
  6. // Checks port.
  7. $url .= ($_SERVER['SERVER_PORT'] != '80') ? $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'] : $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  8.  
  9. // Returns full URL.
  10. return $url;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.