Jump to content


Photo

Sessions Help


  • Please log in to reply
4 replies to this topic

#1 rstrik

rstrik
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 11 June 2006 - 10:19 PM

Hey,

I had a quick question maybe somebody could answer for me. When loading my login page for my members I get these session errors that display at the top of the page. I'm using WAMP5 and haven't had any problems with it so far, so I think it may be in the code. I have checked my Info file and the settings in the php.ini file match the settings listed in the PHP Manual session help section under table 1.0 Any help would be appreciated.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\web\layout.php:2) in C:\web\includes\session.php on line 7

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\web\layout.php:2) in C:\web\includes\session.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at C:\web\layout.php:2) in C:\web\includes\session.php on line 12

This is the where I am creating my session variables in:

login.php
<?php
include $_SERVER['DOCUMENT_ROOT'].'/layout.php';

switch($_REQUEST['req']){

case "validate":
    $validate = @mysql_query("SELECT * FROM members
            WHERE username='{$_POST['username']}'
            AND password = md5('{$_POST['password']}')
            AND verified='1'");

if(mysql_num_rows($validate) == 1){
        while($row = mysql_fetch_assoc($validate)){
            $_SESSION['login'] = true;
            $_SESSION['userid'] = $row['id'];
            $_SESSION['first_name'] = $row['first_name'];
            $_SESSION['last_name'] = $row['last_name'];
            $_SESSION['email_address'] = $row['email_address'];

if($row['admin_access'] == 1){
            $_SESSION['admin_access'] = true;
            }
            $login_time = mysql_query("UPDATE members
            SET last_login=now()
            WHERE id='{$row['id']}'");
            }
header("Location: /loggedin.php");
        } else {
            myheader("Login Failed!");
            echo '<p align ="center">Login Failed</p>';
            echo '<p align ="center">If you have already joined '.
                 'out website, you may need to validate '.
                 'your email address. '.
                 'Please check your email for instructions. ';
            footer();
        }
    break;
default:
        myheader("Login!");
            include $_SERVER['DOCUMENT_ROOT'].'/html/forms/login_form.html';
        footer();
    break;
}
?>





#2 WendyLady

WendyLady
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 11 June 2006 - 10:22 PM

When you get the message "headers already sent" -- the VERY first thing you do is check every included & required file & make sure there aren't any spaces before the first "<?php" or after the last "?>". Also make sure that nowhere in any of those files have you sent anything to be printed or echoed.

Then try surrounding your session code with OB_start(); and OB_flush();. But try the first things first.

Wendy

Edited: HEY! I'm not the first person to figure this out: Go have a look-see: [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=37442\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=37442[/a]

#3 rstrik

rstrik
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 11 June 2006 - 10:40 PM

[!--quoteo(post=382668:date=Jun 11 2006, 05:22 PM:name=WendyLady)--][div class=\'quotetop\']QUOTE(WendyLady @ Jun 11 2006, 05:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
When you get the message "headers already sent" -- the VERY first thing you do is check every included & required file & make sure there aren't any spaces before the first "<?php" or after the last "?>". Also make sure that nowhere in any of those files have you sent anything to be printed or echoed.

Then try surrounding your session code with OB_start(); and OB_flush();. But try the first things first.

Wendy

Edited: HEY! I'm not the first person to figure this out: Go have a look-see: [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=37442\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=37442[/a]
[/quote]

Thanks for the help. Just a FYI the link you so nicely posted says "cannot modify header info" and my skill level doesn't allow me to make assumptions yet and the links are broken in the thread.

#4 WendyLady

WendyLady
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 11 June 2006 - 11:00 PM

rstrik --

While I'm sure there are reasons why you will get "headers already sent" as opposed to "cannot modify headers" -- in my experience so far these errors have been nearly interchangeable in that they have been caused by the same thing. I sent you the link since it goes into more detail. Did you even try the solutions from my earlier post or the other link?

Wendy


#5 rstrik

rstrik
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 12 June 2006 - 02:13 AM

[!--quoteo(post=382675:date=Jun 11 2006, 06:00 PM:name=WendyLady)--][div class=\'quotetop\']QUOTE(WendyLady @ Jun 11 2006, 06:00 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
rstrik --

While I'm sure there are reasons why you will get "headers already sent" as opposed to "cannot modify headers" -- in my experience so far these errors have been nearly interchangeable in that they have been caused by the same thing. I sent you the link since it goes into more detail. Did you even try the solutions from my earlier post or the other link?

Wendy
[/quote]

Yes they fixed the problem, I had extra spaces before I started the PHP engine. I removed them and it
fixed the errors. Thanks for the help.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users