Session_start通过网络无法正常工作,我收到此错误,我该如何解决?

时间:2015-05-21 03:18:17

标签: php mysql

我有2个php页面,第一个是“sample.php”,另一个是“survey.php”。问题是,当我在我的本地机器上运行它工作正常,但当我尝试打开另一台机器通过网络它显示我这个错误。这个错误如下所示在“sample.php”和下面是我的代码为sample.php和survey.php .. sample.php和survey.php中的这个错误就像指向session_start(),我不知道如何解决它。有人请帮我解决这个问题。请... / p>

下面的图片是sample.php的错误

enter image description here

这是sample.php的代码

<body bgcolor="black">
<div class="container-fluid">
    <div class="row header">
        <div class="col-md-12">
            <img src="image/header.png" class="img-responsive">
             <div id="login"><a href="#login-box" class="login-window">Login</a>        </div><!--End of Div login-->
        </div>
    </div>

     <div id="login-box" class="login-popup">
<a href="sample - Copy.php" class="close">Close</a>
 <form method="POST" class="signin" action="" name="Login">
    <fieldset class="textbox">
    <label class="username">
    <span>Username or email</span>
    <input id="username" name="user" value="" type="text" autocomplete="on" placeholder="Username" required/>
    </label>
    <label class="password">
    <span>Password</span>
    <input id="password" name="pass" value="" type="password" autocomplete="on" placeholder="Password" required/>
    </label>
   <button id="submit" type="submit" name="submit">Login</button>  
    </fieldset>
</form>

<?php
if(isset($_POST["submit"])){

if(!empty($_POST['user']) && !empty($_POST['pass'])) {
$user=$_POST['user'];
$pass=$_POST['pass'];

$con=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('region_survey') or die("cannot select DB");

$query=mysql_query("SELECT * FROM survey_login WHERE username='".$user."' AND password='".$pass."'");
$numrows=mysql_num_rows($query);
if($numrows!=0)
{
while($row=mysql_fetch_assoc($query))
{
$dbusername=$row['username'];
$dbpassword=$row['password'];
}

if($user == $dbusername && $pass == $dbpassword)
{
    //Code for alert message
    //after hitting ok redirect to TABLE.php
        //echo "<script>
        //alert('There are no fields to generate a report');
        //window.location.href='admin/ahm/panel';


session_start();

$_SESSION['username']=$user;

/* Redirect browser */
header('location:Survey.php');
}
} 
else {
    //header("Location: sample - Copy.php");
$message = "Invalid Username or Password";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
}
?>

</div><!--End of Pop up Login-->


    <div id="Slider">
        <div class="items">
            <center><img src="image/1.jpg" class="img-responsive"></center>
         </div><!--End of Items-->

         <div class="items">
            <center><img src="image/2.jpg" class="img-responsive"></center>
         </div><!--End of items-->

         <div class="items">
            <center><img src="image/3.jpg" class="img-responsive"></center>
          </div>

          <div class="items">
            <center><img src="image/4.jpg" class="img-responsive"></center>
          </div>

          <div class="items">
            <center><img src="image/5.jpg" class="img-responsive"></center>
          </div>

          <div class="items">
            <center><img src="image/6.jpg" class="img-responsive"></center>
            </div>
    </div><!--End of Slider-->

    <!--Start of Footer-->
    <div class="row footer">
            <p>Copyright © 2015</p>
    </div><!--End of Footer-->

</div><!--End of Cotainer-Fluid-->
</body>
</html>

,这是survey.php的错误

enter image description here enter image description here

,这是survey.php的代码

<?php
session_start();

$conn = mysql_connect("localhost", "root", "");
if(!$conn){
die("Error: ".mysql_error());
}
mysql_select_db("region_survey",$conn);

$result = mysql_query("SELECT * FROM municipality");
?>


<!DOCTYPE html>
<html lang="en">
<head>
<!--<meta charset="UTF-8">-->
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>Region 5 Survey</title>
<link rel="shortcut icon" href="image/icon.ico"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<!--Datatables PLugin-->
<link type="text/css" rel="stylesheet" href="datatable/media/css/jquery.dataTables_themeroller.css">
<link type="text/css" rel="stylesheet" href="datatable/media/css/jquery.dataTables.css">
<script type="text/javascript" src="datatable/media/js/jquery.js"></script>
<script type="text/javascript" src="datatable/media/js/jquery.dataTables.js">   </script>

</head>


<body bgcolor="black">
<div class="container-fluid">
    <div class="row header">
        <div class="col-md-12">
            <img src="image/header.png" class="img-responsive">
            <div id="logout"><a href="logout.php">Logout</a></div><!--End of Div login-->       
        </div>
    </div>



<div id="Session">
<?php
if (@$_SESSION['username'])
    echo "Welcome, ".$_SESSION['username']. "";
else
    header("location:sample - Copy.php");
?>
</div>

<div id="login-box" class="login-popup">
<a href="Survey.php" class="close">Close</a>
<form method="POST" class="signin" action="" name="Add" target="iframe">
    <fieldset class="textbox">
    <label class="Province">
    <span>Province</span>
    <select name="province" class="textfields" id="province" onchange="populate(this.id,'municipality')">
        <option id="">Province</option>
        <option value="Albay">Albay</option>
        <option value="Camnorte">Camarines Norte</option>
        <option value="Camsur1">Camarines Sur 1</option>
        <option value="Camsur2">Camarines Sur 2</option>
        <option value="Catanduanes">Catanduanes</option>
        <option value="Masbate">Masbate</option>
        <option value="Sorsogon">Sorsogon</option>
    </select>
    </label>
    <label class="Date_Submitted">
        <span>Date Submitted</span>
            <input type="date" name="date" id="date" value="">
    </label>

    <label class="Survey_Number">
        <span>Survey Number</span>
            <input id="survey_number" name="survey_number" type="text" value="" autocomplete="on" placeholder="Survey Number">
    </label>
    <label class="Land_Type">
        <span>Land Type</span>
            <input id="land_type" name="land_type" value="" type="text" autocomplete="on" placeholder="Land Type">
    </label>

    <label class="C-Size">
        <span>C-Size</span>
            <input id="c_size" name="c_size" value="" type="number" autocomplete="on" placeholder="C_Size" onKeyPress="return isNumber(event)">
    </label>
    <label class="Contractor">
        <span>Contractor</span>
            <input id="contrctor" name="contractor" value="" type="text" autocomplete="on" placeholder="Contractor">
    </label>

    <label class="Module_Number">
        <span>Module Number</span>
            <input id="module_number" name="module_number" value="" type="text" autocomplete="on" placeholder="Module Number">
    </label>
    <label class="Lad_Target">
        <span>LAD Target</span>
            <input id="Lad_Target" name="Lad_Target" value="" type="text" autocomplete="on" placeholder="LAD Target">
    </label>

    <label class="Fund_Year">
        <span>Fund Year</span>
            <input id="fund_year" name="fund_year" value="" type="text" autocomplete="on" placeholder="Fund Year">
    </label>
    <label class="Land_Category">
        <span>Land Category</span>
            <input id="land_category" name="land_category" value="" type="text" autocomplete="on" placeholder="Land Category">
    </label>
    <label class="Title_Number">
        <span>Title Number</span>
            <input id="title_number" name="title_number" value="" type="text" autocomplete="on" placeholder="Title Number">
    </label>
     <label class="W_Bal">
        <span>W_Bal</span>
            <input id="w_bal" name="w_bal" value="" type="text" autocomplete="on" placeholder="W_Bal">
    </label>

    <label class="Lot_number">
        <span>Lot Number</span>
            <input id="lot_number" name="lot_number" value="" type="text" autocomplete="on" placeholder="Lot Number">
    </label>
    <label class="Project_Number">
        <span>Project Number</span>
            <input id="proj_number" name="proj_number" value="" type="text" autocomplete="on" placeholder="Project Number">
    </label>

    <label class="Agency">
        <span>Agency</span>
            <input id="agency" name="agency" value="" type="text" autocomplete="on" placeholder="Agency">
    </label>
    <label class="Location">
        <span>Location</span>
            <select name="municipality" id="municipality" style="background:#666666; color:#FFFFFF; font-size:13px; height:30px; font-family:Arial, Helvetica, sans-serif;">
                <option id="">Municipality</option>
            </select>
    </label>

    <label class="Date_Surveyed">
        <span>Date Surveyed</span>
            <input id="date_surveyed" name="date_surveyed" value="" type="date">
    </label>
    <label class="No_Lots">
        <span>Number of Lots</span>
            <input id="no_lots" name="no_lots" value="" type="number" autocomplete="on" placeholder="Number of Lots" onKeyPress="return isNumber(event)">
    </label>

    <label class="Area">
        <span>Area</span>
            <input id="area" name="area" value="" type="number" autocomplete="on" placeholder="Area">
    </label>
    <label class="LO_Name">
        <span>Land Owner Name</span>
            <input id="lo_name" name="lo_name" value="" type="text" autocomplete="on" placeholder="Land Owner Name">
    </label>

    <label class="TimesRet">
        <span>Times Returned</span>
            <select name="times_ret" style="background:#666666; color:#FFFFFF; font-size:13px; height:30px; font-family:Arial, Helvetica, sans-serif;">
                <option selected="selected" disabled="disabled">---</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
            </select>
    </label>
    <label class="Times_resub">
        <span>Times Resubmitted</span>
            <select name="times_resub" style="background:#666666; color:#FFFFFF; font-size:13px; height:30px; font-family:Arial, Helvetica, sans-serif;">
                <option selected="selected" disabled="disabled">---</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
            </select>
    </label>

    <label class="Date_Ret1">
        <span>Date Returned 1</span>
            <input id="date_ret" name="date_ret" value="" type="date">
    </label>
    <label class="Date_Resub1">
        <span>Date Resubmitted 1</span>
            <input id="date_resub1" name="date_resub1" value="" type="date">
    </label>

    <label class="Date_Ret2">
        <span>Date Returned 2</span>
            <input id="date_ret2" name="date_ret2" value="" type="date">
    </label>
    <label class="Date_Resub2">
        <span>Date Resubmitted 2</span>
            <input id="date_resub2" name="date_resub2" value="" type="date">
    </label>

    <label class="Date_Ret3">
        <span>Date Returned 3</span>
            <input id="date_ret3" name="date_ret3" value="" type="date">
    </label>
    <label class="Date_Resub3">
        <span>Date Resubmitted 3</span>
            <input id="date_resub3" name="date_resub3" value="" type="date">
    </label>

    <label class="Date_Suspend">
        <span>Date Suspend</span>
            <input id="date_suspend" name="date_suspend" value="" type="date">
    </label>
    <label class="Date_Completed">
        <span>Date Completed</span>
            <input id="date_completed" name="date_completed" value="" type="date">
    </label>

    <label class="Station">
        <span>Station</span>
            <select name="station" style="background:#666666; color:#FFFFFF; font-size:13px; height:30px; font-family:Arial, Helvetica, sans-serif;">
                <option selected="selected" disabled="disabled">---</option>
            </select>
    </label>
    <label class="Date_Approved">
        <span>Date Approved</span>
            <input id="date_approved" name="date_approved" value="" type="date">
    </label>

    <label class="Date_Dar">
        <span>Date DAR</span>
            <input id="date_dar" name="date_dar" value="" type="date">
    </label>
    <label class="Date_PARO">
        <span>Date PARO</span>
            <input id="date_paro" name="date_paro" value="" type="date">
    </label>

    <label class="Cert_40">
        <span>Cert 40</span>
            <input id="cert_40" name="cert_40" value="" type="text" autocomplete="on" placeholder="Cert 40">
    </label>
    <label class="Date_Reported">
        <span>Date Reported</span>
            <input id="date_reported" name="date_reported" value="" type="date">
    </label>
    <br />

    <label class="Remarks">
        <span>Remarks</span>
            <textarea id="remarks" name="remarks" rows="10" cols="60" style="font-family:Arial, Helvetica, sans-serif; font-size:13px;">
            </textarea>
    <br />

    <button id="submit" type="submit" name="submit">Save</button> 
    <button id="submit" type="reset" name="reset">Reset</button>
    </fieldset>
</form>

<iframe src="about:blank" style="display:none" id="iframe" name="iframe"></iframe>

<script type="text/javascript">
var iframe = document.getElementById("iframe");
iframe.onload = function () { formSubmitResponse(iframe); };
function formSubmitResponse(iframe) {
var idocument = (iframe.contentDocument || iframe.contentWindow.document);
if(idocument) {
var responseFromBackend = idocument.getElementsByTagName("body")[0].innerHTML;
}
}
</script>


</div>
<!--End-->
<div class="add_record">   
        <a href="export.php"><input name="image" type="image" value="download" onClick="return confirm('Are you sure you want to download?');" src="image/Download.png" class="img-responsive" width="40px" height="40px"></a>
    </div>



<form action="delete.php" method="post">

<div class="add_record">   
        <input name="image" type="image" value="delete" onClick="return confirm('Are you sure you want to delete?');" src="image/DELETE.png" class="img-responsive" width="40px" height="40px">
    </div>

<div class="add_record">
        <a href="#login-box" class="login-window"><input name="images" type="image" value="add" src="image/Add_record.ico" class="img-responsive" width="40px" height="40px"></a>
     </div>


     <div id="clear">
     </div>
    <hr>
    <br />



    <div id="datatable_wrapper">
        <table id="datatables" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>LO&nbsp;Name</th>
                    <th>Province</th>
                    <th>Location</th>
                    <th>Title&nbsp;Number</th>
                    <th>Lot&nbsp;Number</th>
                    <th>Survey&nbsp;Status</th>
                    <th>Survey&nbsp;Number</th>
                    <th>Project&nbsp;No</th>
                    <th>Module&nbsp;No</th>
                    <th>Area</th>
                    <th>Date&nbsp;Approved</th>
                    <th>Received&nbsp;by&nbsp;DAR</th>
                    <th>To&nbsp;PARO</th>
                    <th>Date&nbsp;Surveyed</th>
                    <th>Date&nbsp;Submitted</th>
                    <th>Ret1</th>
                    <th>Resub1</th>
                    <th>Ret2</th>
                    <th>Resub2</th>
                    <th>Ret3</th>
                    <th>Resub3</th>
                    <th>Fund&nbsp;Year</th>
                    <th>Remarks</th>
                    <th>Action</th>
               </tr>
            </thead>
        <tbody>
    <?php
//Loop through the result set just as you would loop
//through a normal mysql result set
while($row = mysql_fetch_array($result)){
    ?>
        <tr>
        <td><?php echo $row['id']; ?></td>
        <td><?php echo $row['province_id']; ?></td>
        <td><?php echo $row['municipality_name']; ?></td>
        <td><input name="selector[]" type="checkbox"
id="checkbox[]" value="<?php echo $row['id'];?>">&nbsp;
        <a href="update.php<?php echo '?id='.$row['id']; ?>">Edit</a></td>

    </tr>
<?php
    }
?>
      </tbody>
   </table>
    </div>

</form>
    <!--Start of Footer-->
    <div class="row footer">
            <p>Copyright © 2015</p>
    </div><!--End of Footer-->

</div><!--End of Cotainer-Fluid-->
</body>
</html>

2 个答案:

答案 0 :(得分:1)

PHP session_start()只能在网页中回显任何内容之前启动,即网页上的任何输出。以下是您正在使用已弃用的mysql_*函数,因此在会话开始之前您将收到该错误消息。我建议您使用mysqli_*PDO。暂时使用以下方法关闭页面中的警告消息和错误消息:

error_reporting(0); //or
ini_set('display_errors', 0);

答案 1 :(得分:1)

您需要将PHP配置为不呈现E_DEPRECATED通知,或修复弃用通知。您应该使用mysqli而不是mysql客户端。

在会话开始之前,不能将任何输出发送回浏览器。

在你的php.ini

error_reporting = E_ALL & ~E_DEPRECATED

或者在你的剧本中:

ini_set("error_reporting", E_ALL & ~E_DEPRECATED);