Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Login Script Help
Dynasty
post Jul 4 2005, 07:39 PM
Post #1


Newbie [Level 1]
*

Group: Members
Posts: 24
Joined: 30-June 05
Member No.: 8,848



My friend helped me create a login script. But there is a error that shows up on the page. I am able to connect to the database and login in and everything but theres an error on the page.

CODE
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/dynasty/public_html/New Folder/db_connect.php:9) in /home/dynasty/public_html/New Folder/check_login.php on line 13


Can someone tell me whats wrong. Im new to php and mysql. So please be gentle sad.gif
Go to the top of the page
 
+Quote Post
rejected
post Jul 4 2005, 08:00 PM
Post #2


{([Mod])}
*********

Group: Members
Posts: 710
Joined: 30-October 04
From: Texas
Member No.: 2,058



I'm not sure that I can do much without knowing what is in

QUOTE
/home/dynasty/public_html/New Folder/db_connect.php:9) and
/home/dynasty/public_html/New Folder/check_login.php on line 13
Go to the top of the page
 
+Quote Post
Dynasty
post Jul 4 2005, 08:20 PM
Post #3


Newbie [Level 1]
*

Group: Members
Posts: 24
Joined: 30-June 05
Member No.: 8,848



CODE
session_start();

That is line 13.

CODE
<?php

/* check login script, included in db_connect.php. */

session_start();

if (!isset($_SESSION['username']) || !isset($_SESSION['password'])) {
$logged_in = 0;
return;
} else {

// remember, $_SESSION['password'] will be encrypted.

if(!get_magic_quotes_gpc()) {
 $_SESSION['username'] = addslashes($_SESSION['username']);
}


// addslashes to session username before using in a query.
$pass = $db_object->query("SELECT password FROM users WHERE username = '".$_SESSION['username']."'");

if(DB::isError($pass) || $pass->numRows() != 1) {
 $logged_in = 0;
 unset($_SESSION['username']);
 unset($_SESSION['password']);
 // kill incorrect session variables.
}

$db_pass = $pass->fetchRow();

// now we have encrypted pass from DB in
//$db_pass['password'], stripslashes() just incase:

$db_pass['password'] = stripslashes($db_pass['password']);
$_SESSION['password'] = stripslashes($_SESSION['password']);



//compare:



if($_SESSION['password'] == $db_pass['password']) {
 // valid password for username
 $logged_in = 1; // they have correct info
    // in session variables.
} else {
 $logged_in = 0;
 unset($_SESSION['username']);
 unset($_SESSION['password']);
 // kill incorrect session variables.
}
}


// clean up
unset($db_pass['password']);

$_SESSION['username'] = stripslashes($_SESSION['username']);

?>

That is the whole script if you need it.
Go to the top of the page
 
+Quote Post
bureX
post Jul 4 2005, 09:03 PM
Post #4


Super Member
*********

Group: Members
Posts: 318
Joined: 5-January 05
Member No.: 3,136



I had a similar problem, and I read somewhere that the PHP.ini file should be edited, so:

I changed this line:
session.auto_start= 0 ; initialize session on request startup
To this:
session.auto_start= 1 ; initialize session on request startup

If anyone has a better solution for this, I would really like to hear it please, because you can't edit the PHP.ini file on a remote server, only locally.

I have no idea what it does, but I will look it up on www.php.net later...
Go to the top of the page
 
+Quote Post
SystemWisdom
post Jul 4 2005, 09:48 PM
Post #5


Advanced Member
*******

Group: Members
Posts: 117
Joined: 3-May 05
From: A Canadian South of the 49th Parallel
Member No.: 6,544



I am guessing you have some white-space (or anything) that is being output to the browser (meaning it is not inside of any PHP tags) in your /home/dynasty/public_html/New Folder/db_connect.php file at line 9.

In order to use sessions, you must start your session before outputting *anything* to the browser.. Even white-space will cause this error for you, if the white-space is output before the call to session_start()..
Go to the top of the page
 
+Quote Post
fffanatics
post Jul 4 2005, 10:53 PM
Post #6


Privileged Member
*********

Group: [HOSTED]
Posts: 937
Joined: 14-April 05
From: West Chester, PA
Member No.: 5,636



yeah make sure u do not have any empty lines after the ?> or even a blank space after it because if you do you get that error.
Go to the top of the page
 
+Quote Post
bureX
post Jul 4 2005, 11:13 PM
Post #7


Super Member
*********

Group: Members
Posts: 318
Joined: 5-January 05
Member No.: 3,136



Sorry, but you are wrong! The session_start() line has to be started BEFORE ANY DATA IS OUTPUTTED to the browser! So, you can have white spaces, comments or php code before the session_start() function, but you cannot have a, let's say, <body> tag before it, or use the echo() command before the session is started!

This code:
CODE

<?php
$thisvariable="nothing";
session_start();
echo("<meta http-equiv=\"Cache-Control\" content=\"private\">");
?>


..is valid!

But, this code:
CODE

<?php
$thisvariable="nothing";
echo("<meta http-equiv=\"Cache-Control\" content=\"private\">");
session_start();
?>


... is invalid! The echo() command outputs data to the browser before the session is started!
Go to the top of the page
 
+Quote Post
Dynasty
post Jul 5 2005, 01:58 AM
Post #8


Newbie [Level 1]
*

Group: Members
Posts: 24
Joined: 30-June 05
Member No.: 8,848



Thank you bureX. You were right about the body thing. I forgot to erase the previous code i had. laugh.gif My fualt. Thanks for all the help and suggestions.
Go to the top of the page
 
+Quote Post
SystemWisdom
post Jul 5 2005, 03:36 PM
Post #9


Advanced Member
*******

Group: Members
Posts: 117
Joined: 3-May 05
From: A Canadian South of the 49th Parallel
Member No.: 6,544



QUOTE(bureX @ Jul 4 2005, 07:13 PM)
Sorry, but you are wrong! The session_start() line has to be started BEFORE ANY DATA IS OUTPUTTED to the browser! So, you can have white spaces, comments or php code before the session_start() function, but you cannot have a, let's say, <body> tag before it, or use the echo() command before the session is started!
*




I am not wrong, nor is the PHP online documentation.. You can go and argue this fact with the PHP developers if you want to..

Read:
session_start

Quoting the page:
QUOTE
Note: If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.


In most cases PHP will use cookie-based sessions (to store session id) unless the users browser doesn't accept cookies, then it will use the querystring method..


You see, when outputting *anything* to the browser (including white-space) the PHP processor first must prepare and send the MIME Type Headers for the requested page. If *any* output is sent to the client *before* session_start() then PHP has to send the Headers first. If the headers are sent before calling session_start() then PHP will not be able to append the SessionID to the page headers, and thus you will receive an error..

I didn't make this up, it IS the way PHP works!