AW: [PHP-WIN] session help
| From: | (Sven Schnitzke) | Date: | Fri, 25 Apr 2003 11:38:04 +0000 |
| Subject: | AW: [PHP-WIN] session help | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-19613@lists.php.net to get a copy of this message | ||
Hi Matt,
this "headers already sent" thing may come with session
handling and some other situations where you specify the
behaviour realized via "header:" items in HTTP.
Basically you have to make sure you don't output ANYTHING
(not even a white space) before all header related stuff is
handled.
This is because HTTP requests have a header part sent en bloc
at the top of a message and a body part to follow, the header part
being good for all org (content type, charset, sessions, auth, ...)
and the body part being what shall make up the content.
PHP parses a HTML doc, executing everything it gets hold
of top to bottom. The first content output to be generated
triggers output of the headers known up to then.
If it eases control flow (header info being calculated from
content generated) you might want to use output buffering
http://www.php.net/manual/en/ref.outcontrol.php
to hold back page output thereby having the chance to
put "afterthoughts" into your headers.
--
Sven
> -----Ursprüngliche Nachricht-----
> Von: Matt Palermo [SMTP:mpalermo@vt.edu]
> Gesendet am: Freitag, 25. April 2003 12:27
> An: php-windows@lists.php.net
> Betreff: [PHP-WIN] session help
>
> 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
>
>
> $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
>
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>