Created
March 11, 2012 04:34
-
-
Save jehoshua02/2015043 to your computer and use it in GitHub Desktop.
Determine url base reliably
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Controller { | |
private $_base_url; | |
// ... | |
public function base_url() | |
{ | |
if (empty($this->_base_url)) | |
{ | |
$https = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); | |
$protocol = ($https) ? 'https' : 'http'; | |
$host = $_SERVER['HTTP_HOST']; | |
$path = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); | |
$this->_base_url = $protocol . '://' . $host . $path; | |
} | |
return $this->_base_url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment