doubi8512 2014-05-28 21:49 采纳率: 0%
浏览 47

强制页面打破安全协议(https://> http://)

I used info from this answer (https://stackoverflow.com/a/85867/3271766 - along with the contribution from Dave1010) to allow me to force a page to load securely (https://). This works beautifully!

Now, I want to do the opposite. When clicking a relative link (to a normal, non-secure page) from a secure page, I want to force that page to load non-securely (http://). I don't want to use absolute links to accomplish this. They need to stay relative. Instead, I'd rather use a piece of PHP code similar to what I used to force pages to load securely.

How can this be done? Thanks, in advance, for your help.

The code I used (in each page's head tags) to force pages to load securely is:

<?php
    // WORKING: FORCE SECURE - Force page to load securely (http:// > https://)
    if(empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] !== "on")
    {
        header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
        exit();
    }
?>

I tried the following, but it stops the page from loading altogether:

<?php
    // NOT WORKING: FORCE NON-SECURE - Force page to break out of secure protocol (https:// > http://)
    if(empty($_SERVER["HTTP"]) || $_SERVER["HTTP"] !== "on")
    {
        header("Location: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
        exit();
    }
?>

Is there a way to modify this to make it work?

(By the way, in case anyone is wondering, I am doing this because a third-party sharing tool my client wants to use does not have a valid security certificate. Thus, portions of the sharing tool either do not load, or do not function. I have contacted the vendor repeatedly, but they have not responded. I have removed the tool from the secure pages only. However, my client wants to use this tool on all other pages, on which it works perfectly, so long as it is not accessed securely.) :-)

Regards, Jeremy

  • 写回答

1条回答 默认 最新

  • dongshi3361 2014-05-28 21:51
    关注

    Change

    if(empty($_SERVER["HTTP"]) || $_SERVER["HTTP"] !== "on")
    

    to

    if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'){
        $url = 'http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
        header("Location: $url");
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?