-1

I keep getting this error when going into another page while logged in:

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

Also, whenever i put call update.php directly (while not logged in), it's not supposed to show the form, it's supposed to direct you back to the login page. I spent hours on this and cant figure out what im doing wrong. ANY help would be appreaciated.

Here's my code: 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>'; 
 }; 
?>

UPDATE.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"];
?>

PASSWORDS.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"); 

      }; 
}; 
kamil234
  • 23
  • 6

2 Answers2

0

Try insert session_start(); into PASSWORDS.PHP and delete it in other files. I think that than it work.

mrakodol
  • 1,143
  • 3
  • 12
  • 41
0

You cannot output anything to the user before the start of the session. Your update.php file also does not echo the form to the user.

chaoskreator
  • 889
  • 1
  • 17
  • 39