Jump to content

Archived

This topic is now archived and is closed to further replies.

rstrik

Sessions Help

Recommended Posts

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.

[code]
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[/code]

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

login.php
[code]
<?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;
}
?>
[/code]


Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[!--quoteo(post=382668:date=Jun 11 2006, 05:22 PM:name=WendyLady)--][div class=\'quotetop\']QUOTE(WendyLady @ Jun 11 2006, 05:22 PM) [snapback]382668[/snapback][/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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[!--quoteo(post=382675:date=Jun 11 2006, 06:00 PM:name=WendyLady)--][div class=\'quotetop\']QUOTE(WendyLady @ Jun 11 2006, 06:00 PM) [snapback]382675[/snapback][/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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.