admin管理员组

文章数量:1194126

I have the following php script which works flawlessly in normal circumstances (i.e. visiting the page directly):

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/contact_search.css" />
<script type="text/javascript" src=".4.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.watermarkinput.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$(document).click(function() {
    $("#display").hide();
});

var cache = {};

    $("#searchbox").keyup(function() {
        var searchbox = $(this).val();
        var dataString = 'searchword=' + searchbox;

        if (searchbox.length < 3 ) {
            $("#display").hide();
            } else {

            $.ajax({
                type: "POST",
                url: "contact_search/search.php",
                data: dataString,
                cache: false,
                success: function(html) {

                    $("#display").html(html).show();
                }
            });
        return false;
    });
});

jQuery(function($) {
    $("#searchbox").Watermark("Search for Group");
});
</script>
</head>

<body bgcolor="#e0e0e0">
<div class="body">


          <div class="liquid-round" style="width:100%;">
            <div class="top"><span><h2>Contacts List</h2></span></div>

            <div class="center-content"> 
                <img src="images/search.gif" style="float:right;" />
                <input type="text" id="searchbox" maxlength="20" value="<?php echo $_SESSION['hello'];?>" />
                <div id="display"></div><div style="clear:both;"></div>

            </div>

            <div class="bottom"><span></span></div>
        </div>


        <div class="liquid-round" style="width:97%;">
            <div class="top"><span><h2>My Messages</h2></span></div>

            <div class="center-content" style="min-height:200px;">                        
            </div>

            <div class="bottom"><span></span></div>
        </div>    


</div>
</body>
</html>

HOWEVER - when I add the following piece to the top of the page, the javascript/jquery functions simply stop working altogether.

<?php
    session_start();

    if( $_SERVER['SERVER_PORT'] == 80) {
        header('Location:https://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]); 
        die();
    }
?>

These pages require login so I need to ensure they are https protected but this error messes all that up. Any ideas what could be causing the issue?

I have the following php script which works flawlessly in normal circumstances (i.e. visiting the page directly):

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/contact_search.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.watermarkinput.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$(document).click(function() {
    $("#display").hide();
});

var cache = {};

    $("#searchbox").keyup(function() {
        var searchbox = $(this).val();
        var dataString = 'searchword=' + searchbox;

        if (searchbox.length < 3 ) {
            $("#display").hide();
            } else {

            $.ajax({
                type: "POST",
                url: "contact_search/search.php",
                data: dataString,
                cache: false,
                success: function(html) {

                    $("#display").html(html).show();
                }
            });
        return false;
    });
});

jQuery(function($) {
    $("#searchbox").Watermark("Search for Group");
});
</script>
</head>

<body bgcolor="#e0e0e0">
<div class="body">


          <div class="liquid-round" style="width:100%;">
            <div class="top"><span><h2>Contacts List</h2></span></div>

            <div class="center-content"> 
                <img src="images/search.gif" style="float:right;" />
                <input type="text" id="searchbox" maxlength="20" value="<?php echo $_SESSION['hello'];?>" />
                <div id="display"></div><div style="clear:both;"></div>

            </div>

            <div class="bottom"><span></span></div>
        </div>


        <div class="liquid-round" style="width:97%;">
            <div class="top"><span><h2>My Messages</h2></span></div>

            <div class="center-content" style="min-height:200px;">                        
            </div>

            <div class="bottom"><span></span></div>
        </div>    


</div>
</body>
</html>

HOWEVER - when I add the following piece to the top of the page, the javascript/jquery functions simply stop working altogether.

<?php
    session_start();

    if( $_SERVER['SERVER_PORT'] == 80) {
        header('Location:https://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]); 
        die();
    }
?>

These pages require login so I need to ensure they are https protected but this error messes all that up. Any ideas what could be causing the issue?

Share Improve this question asked Nov 5, 2010 at 16:07 JM4JM4 6,78818 gold badges79 silver badges128 bronze badges 1
  • 1 Is there any javascript errors? Also you should have a local copy of jQuery or change the http to https so that you don't get any of the security errors about it being on a non secure site. – Nalum Commented Nov 5, 2010 at 16:11
Add a comment  | 

2 Answers 2

Reset to default 36

It's probably the browser not displaying insecure (http) content on https pages, there's a simple fix though, use a scheme relative URL, like this:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>

This way you'll get http://ajax.googleapis.com/.... on the http:// version of your page and https://ajax.googleapis.com/.... on the https:// version.

Since session_start produces HTTP-Headers I recommend to do the port check before session_start.

But, these lines should not affect your JS in any circumstances, because the redirect to HTTPS is independend from the fact if your site is working via HTTPS. So, if you are not sure, remove the lines and access your page with HTTPS. Bring JS to work there. And afterwards implement the redirect.

本文标签: phpDoes HTTPS connection disabled jQueryStack Overflow