utils.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. function isSuperGlobal($name){
  3. switch($name){
  4. case 'GLOBALS':
  5. case '_SERVER':
  6. case '_GET':
  7. case '_POST':
  8. case '_FILES':
  9. case '_COOKIE':
  10. case '_SESSION':
  11. case '_REQUEST':
  12. case '_ENV': return true; break;
  13. default: return false; break;
  14. }
  15. }
  16. function i($i = '') {
  17. foreach($GLOBALS as $key=>$val){
  18. if(!isSuperGlobal($key))
  19. global $$key;
  20. }
  21. ob_start();
  22. global $basedir;
  23. include $basedir . 'pages/' . $i . '.php';
  24. return ob_get_clean();
  25. }
  26. function url($url = '') {
  27. global $baseurl;
  28. return $baseurl . $url;
  29. }
  30. function url_origin($s, $use_forwarded_host=false) {
  31. $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true:false;
  32. $sp = strtolower($s['SERVER_PROTOCOL']);
  33. $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
  34. $port = $s['SERVER_PORT'];
  35. $port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
  36. $host = ($use_forwarded_host && isset($s['HTTP_X_FORWARDED_HOST'])) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : $s['SERVER_NAME']);
  37. return $protocol . '://' . $host;
  38. }
  39. function full_url($s, $use_forwarded_host=false) {
  40. return url_origin($s, $use_forwarded_host) . $s['REQUEST_URI'];
  41. }