php 判断 http 还是 https ,以及获得当前 url 的方法

php 判断 http 还是 https ,以及获得当前 url 的方法

$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https' : 'http';
if ($http_type === "http") {
    $baseUrl = Url::base('http');
} else {
    $baseUrl = Url::base('https');
}
adays
讨论数量: 3

此办法太low了, 正确的办法是直接 用 : // 即可,这样他自动的识别出来

3年前 评论
VeryCool 3年前
随波逐流
// 解析url
$url = "https://www.baidu.com/index.php?tn=monline_6_dg"
echo print_r(parse_url($url));die;
// 打印
Array
(
    [scheme] => https
    [host] => www.baidu.com
    [path] => /index.php
    [query] => tn=monline_6_dg
)
3年前 评论
VeryCool

   $url = "https://www.baidu.com/index.php?tn=monline_6_dg"
   $http_type =  explode('://',$url)[0];

额 这应该是1楼的方法 网址借二楼的

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!