dongziya9863 2009-05-23 06:06
浏览 22

如何通过PHP检查Web服务器上是否存在ssl?

I have this function in a class:

function enable_ssl() {
    if ($_SERVER[HTTPS] != "on") {
        $domain = "https://".$_SERVER['HTTP_HOST'] . "/" . $_SERVER['SCRIPT_NAME'];
        header("Location: {$domain}");
    }
}

The problem is that when the server doesn't have SSL installed and I have this function initiating the page redirects to a 404 page. I was wondering how I can have this function work only when SSL is installed and working?

Is it possible?

Thanks.

P.S.: I did some Google research but couldn't find much of anything.

  • 写回答

8条回答 默认 最新

  • duangang3832 2009-05-23 06:16
    关注

    On a *nix server, you could try parsing the output of netstat -A inet -lnp for a web server listening on port 443. Kinda clunky.

    Better option, I'd say, is to make it a configuration option for the user. Let them tell your app if they've got HTTPS enabled.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀