Jump to content

[SOLVED] Logging into an account on my website


EPCtech

Recommended Posts

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

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

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 ;D

 

however, in saying that, if session_start(); comes first in the file, then session variables can be used anywhere with in the file.

Archived

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

×
×
  • Create New...

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.