EPCtech Posted July 30, 2008 Share Posted July 30, 2008 Hello, I have the following code for logging in, but something went wrong: // Start the session (DON'T FORGET!!) session_start(); // Check if user wants to login (GET info) if(isset($_GET['try'])) { // That's nice, user wants to login. But lets check if user has filled in all information If(empty($_POST['username']) OR empty($_POST['password'])) { // User hasn't filled it all in! echo 'Please fill in <b>ALL</b> the fields. All fields are required.'; } else { // User filled it all in! // Make variables save with addslashes and md5 $username = addslashes($_POST['username']); $password = md5($_POST['password']); // Search for a combination $query = mysql_query("SELECT id FROM login WHERE username = '" . $username . "' AND password = '" . $password . "' ") or die(mysql_error()); // Save result list($user_id) = mysql_fetch_row($query); // If the user_id is empty no combination was found if(empty($user_id)) { echo '<b>Error:</b> User or password entered is not correct, or user does not exist.'; } else { // the user_id variable doesn't seem to be empty, so a combination was found! // Create new session, store the user id $_SESSION['user_id'] = $user_id; echo("You have been successfully logged in!<br /><a href='usercp'>User Control Panel</a>"); } } } Error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/---------/public_html/login.php:74) in /home/---------/public_html/login.php on line 16 Can someone see any problem here? Best Regards, En-Psyche Management Link to comment https://forums.phpfreaks.com/topic/117284-solved-logging-into-an-account-on-my-website/ Share on other sites More sharing options...
chacha102 Posted July 30, 2008 Share Posted July 30, 2008 You've sent white space or character out before you try to start the session. Spaces, Characters, or anything similar will prevent you from starting a session, because starting a session creates a cookie, and cookies can only be made before any page output is sent Link to comment https://forums.phpfreaks.com/topic/117284-solved-logging-into-an-account-on-my-website/#findComment-603308 Share on other sites More sharing options...
chacha102 Posted July 30, 2008 Share Posted July 30, 2008 Here is a more complete post about headers http://www.phpfreaks.com/forums/index.php/topic,95562.0.html Link to comment https://forums.phpfreaks.com/topic/117284-solved-logging-into-an-account-on-my-website/#findComment-603309 Share on other sites More sharing options...
MasterACE14 Posted July 30, 2008 Share Posted July 30, 2008 session_start(); needs to go at the VERY TOP straight after the very first <?php in the page. Link to comment https://forums.phpfreaks.com/topic/117284-solved-logging-into-an-account-on-my-website/#findComment-603324 Share on other sites More sharing options...
trq Posted July 30, 2008 Share Posted July 30, 2008 session_start(); needs to go at the VERY TOP straight after the very first <?php in the page. That isn't exactly correct. session_start() can go anywhere, it just need be before any output is sent to the browser. Link to comment https://forums.phpfreaks.com/topic/117284-solved-logging-into-an-account-on-my-website/#findComment-603328 Share on other sites More sharing options...
MasterACE14 Posted July 30, 2008 Share Posted July 30, 2008 That isn't exactly correct. session_start() can go anywhere, it just need be before any output is sent to the browser. oh, cool, I didn't know that. Thanks for the heads up however, in saying that, if session_start(); comes first in the file, then session variables can be used anywhere with in the file. Link to comment https://forums.phpfreaks.com/topic/117284-solved-logging-into-an-account-on-my-website/#findComment-603350 Share on other sites More sharing options...
chacha102 Posted July 30, 2008 Share Posted July 30, 2008 It can't have to come first in the file because then that would annoy all of the OOP Maniacs that will create a Class to deal with Sessions! Link to comment https://forums.phpfreaks.com/topic/117284-solved-logging-into-an-account-on-my-website/#findComment-603613 Share on other sites More sharing options...
EPCtech Posted July 30, 2008 Author Share Posted July 30, 2008 Thanks everyone, it worked. Just inserted the session_start(); at the beginning. Best Regards, En-Psyche Management Link to comment https://forums.phpfreaks.com/topic/117284-solved-logging-into-an-account-on-my-website/#findComment-604042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.