看到你,梁松远的博客

位置 » 主页 » 代码分享 » 获取站点根目录 URL

获取站点根目录 URL

 /**

 * 获取站点根目录 URL
 *
 * @return string
 */
function base_url()
{
$clean_url = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : NULL;
$clean_url = dirname(rtrim($_SERVER['PHP_SELF'], $clean_url));
$clean_url = rtrim($_SERVER['HTTP_HOST'] . $clean_url, '/\\');
 
$scheme = ($_SERVER['HTTPS'] AND !in_array(strtolower($_SERVER['HTTPS']), array('off', 'no'))) ? 'https' : 'http';
 
return $scheme . '://' . $clean_url;
}