2018年4月12日 星期四

CodeIgniter(getBaseUrl())

function getBaseUrl() {
    $path = $_SERVER['SCRIPT_NAME'];
    $serverName = $_SERVER['SERVER_NAME'];
    $port = $_SERVER['SERVER_PORT'];

    $path = preg_replace("/\/index.*/i", '', $path);

    $baseUrl = sprintf('%s:%s%s', $serverName, $port, $path);
    return $baseUrl;
}