-1

登录时进入另一个页面时,我不断收到此错误:

Warning: session_start() [function.session-start]: Cannot send session cache limiter -      headers already sent (output started at     /home/content/63/10400363/html/SeniorProject/update.php:5) in      /home/content/63/10400363/html/SeniorProject/update.php on line 6

此外,每当我直接调用 update.php 时(未登录时),它不应该显示表单,它应该将您引导回登录页面。我花了几个小时在这上面,无法弄清楚我做错了什么。任何帮助将不胜感激。

这是我的代码:LOGIN.PHP

<?php 
session_start(); 
require("passwords.php");
?>
<?php
function redirect(){    
    echo '<META HTTP-EQUIV="Refresh" Content="0; URL=update.php">';    
    exit;    
};
if ($_POST["ac"]=="log") { /// do after login form is submitted  
     if ($USERS[$_POST["username"]]==$_POST["password"]) { /// check if submitted 
    // username and password exist in $USERS array 
          $_SESSION["logged"]=$_POST["username"]; 
     } else { 
          echo 'Incorrect username/password. Please, try again.'; 
     }; 
}; 
if (array_key_exists($_SESSION["logged"],$USERS)) { //// check if user is logged or not  
     echo '<center><font color="red">You are logged in.</font></center>';
     echo '<center><font color="red">You will be redirected to the correct page in     3 seconds.</font></center>';
     echo "Your session is running " . $_SESSION["logged"];



} else { //// if not logged show login form 
     echo '<form action="login.php" method="post"><input type="hidden" name="ac"     value="log"> '; 
     echo 'Username: <input type="text" name="username" />'; 
     echo 'Password: <input type="password" name="password" />'; 
     echo '<input type="submit" value="Login" />'; 
     echo '</form>'; 
 }; 
?>

更新.PHP

<?php
session_start();  
require("passwords.php");
check_logged();
?>
<?php


'<p align="center">
<h1>UPDATE RECORDS</h1>
<form method="post" action="doupdate.php">
    <fieldset>
    <legend> Update Form: </legend>
    <font color="red">PROF. ID*</font> <br>
    <input name="id" type="text" size="50" /><br>
    <font color="red">BUILDING* </font> <br>
    <input name="building" type="text" size="50" /><br>
    <font color="red">ROOM NUM* </font> <br>
    <input name="roomNum" type="text" size="50" /><br>
    <font color="red">OFFICE HR* </font> <br>
    <input name="officeHr" type="text" size="50" /><br>
    <font color="red">SPECIAL REMARKS </font> <br>
    <input name="special" type="text" size="50" /><br><br>
    <input name="submit" type="submit" value="submit" />

    </fieldset><br><br>
</form>
<font color="red">* REQUIRED FIELDS<br>
OFFICE HOURS UPDATED IN FOLLOWING FORMAT:<br>
M/TH 00:00-11:11</font><br>

</html>';
echo "Your session is running " . $_SESSION["logged"];
?>

密码.PHP

 //OMITTED PASSWORDS ARRAY HERE
 //OMITTED PASSWORDS ARRAY HERE
 //OMITTED PASSWORDS ARRAY HERE
 //OMITTED PASSWORDS ARRAY HERE


function check_logged(){ 
     global $_SESSION, $USERS; 
     if (!array_key_exists($_SESSION["logged"],$USERS)) { 
          header("Location: login.php"); 

      }; 
}; 
4

2 回答 2

0

尝试插入 session_start(); 进入 PASSWORDS.PHP 并在其他文件中删除它。我认为这比它有效。

于 2013-02-25T20:06:21.403 回答
0

在会话开始之前,您不能向用户输出任何内容。您的 update.php 文件也不会将表单回显给用户。

于 2013-02-25T20:10:18.097 回答