Re: session help
| From: | Seung Hwan Kang | Date: | Fri, 25 Apr 2003 10:45:36 +0000 |
| Subject: | Re: session help | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-19612@lists.php.net to get a copy of this message | ||
session_start() has to be at the beginning.
Matt Palermo wrote:
I am having trouble using sessions to tell if a user is logged in or not. I have attached some of the code I am using for it. <?php session_start();
$conn=mysql_connect($dbServer,$dbUsername,$dbPassword); $dbase=mysql_select_db($db,$conn); $check=mysql_query("SELECT requireaccount FROM calendar_config"); $row=mysql_fetch_row($check); if($action=="logger"||$MyLogin=="true") { //> session_start();
$errors=0; $usercheck=mysql_query("SELECT * FROM calendar_users WHERE username='$uname'&&password='$pword'"); while($row=mysql_fetch_assoc($usercheck)) { $userid=$row[recno]; $namer=$row[username]; $emailaddy=$row[email]; $priv=$row[priv]; } if($userid=="") { die("<center>You don't have and account, or your username and password don't match.<br><a href='javascript:history.back()'>Go back and try again</a></center>"); } elseif($priv=="N"||$priv=="") { die("<center>User: <b>$namer</b> must be approved by the calendar administrator or have sufficient privileges to add events to the calendar.<br><a href='javascript:history.back()'>Go Back</a></center>"); } else { if($MyLogin!="true") { $_session["MyUserID"]=$userid; $_session["MyLogin"]="true"; } } //then the rest of the code comes after this. When I go to access this, I get the following: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\calendar\header.php:5) in C:\Program Files\Apache Group\Apache2\htdocs\calendar\add_event.php on line 10 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\calendar\header.php:5) in C:\Program Files\Apache Group\Apache2\htdocs\calendar\add_event.php on line 10 Anyone know why? Matt