Posted By

mladoux on 04/08/11


Tagged

urllinkhelper


Versions (?)

base_url


 / Published in: PHP
 

Just a little link helper that I did for a friend.

  1. <?php
  2. define('PATH', str_replace("\\", '/', str_replace(SELF, '', __FILE__)));
  3. define('URI', str_replace(SELF, '', $_SERVER['SCRIPT_NAME']));
  4.  
  5. /**
  6.  * function site_url
  7.  *
  8.  * ex. site_url('path/to/file');
  9.  */
  10.  
  11.  
  12. function site_url($path) {
  13. if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
  14. $base_url = "https://{$_SERVER['SERVER_NAME']}".URI;
  15. } else {
  16. $base_url = "http://{$_SERVER['SERVER_NAME']}".URI;
  17. }
  18.  
  19. if($base_url[str_len($base_url) - 1] != '/') $base_url = $base_url.'/';
  20.  
  21. return $base_url.$path;
  22. }
  23.  
  24. ?>

Report this snippet  

You need to login to post a comment.