开发者

Apache PHP 5 header() Problem SSL domains

开发者 https://www.devze.com 2023-03-16 03:12 出处:网络
I wondered if any one has seen this problem before and开发者_运维百科 if you have an answer on how to fix it. Basically I have a pages that are SSL encrypted, and ones that don\'t/can\'t be encrypted

I wondered if any one has seen this problem before and开发者_运维百科 if you have an answer on how to fix it. Basically I have a pages that are SSL encrypted, and ones that don't/can't be encrypted (due to a plugin dependancy) So on the pages that are none SSL I detect a header and try and redirect to the HTTP version of the page:

if($_SERVER["HTTPS"] == "on")
{
  header("HTTP/1.1 301 Moved Permanently");
  header("Location: http://www.example.com");
  exit();
}

However PHP seems to block me redirecting from the secure domain to the non secure site of the same domain!

If i go from https://www.example.com -> http://www.secondsite.com it works but, https://www.example.com -> http://www.example.com forces me to stay on the encrypted site and results in an endless redirect.

Any pointers??

Ric


You could maybe make sure your headers have not been sent already which might be the case as keeping on the same page. See this from php manual :

function redirect($url, $debug=FALSE){

// If headers not sent yet... then do php redirect
if (!headers_sent()) {
    header('Location: '.$url);
    exit;
// if headers are already sent... do javascript redirect... if javascript is disabled, do html redirect.
} else {

    // Js redirect
    echo '<script type="text/javascript">';
    echo "<!--";
    echo 'window.location.href="'. $url .'";';
    echo "//-->";
    echo '</script>';

    // HTML redirect if js disabled
    echo '<noscript>';
    echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
    echo '</noscript>';
}
}//==== End -- Redirect  
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号