Jump to content

Error Message


Imoddedu
 Share

Recommended Posts

I don't really get how to troubleshoot this error message.Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /public_html/opxtest/web/login.php:9) in /home1/suitefou/public_html/opxtest/web/login.php on line 38Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /public_html/opxtest/web/login.php:9) in /home1/suitefou/public_html/opxtest/web/login.php on line 38Warning: Cannot modify header information - headers already sent by (output started at /home1/suitefou/public_html/opxtest/web/login.php:9) in /public_html/opxtest/web/login.php on line 53here is the code.

<?php	if($_POST) {		$dbhost = '*****';		$dbuser = '*****';		$dbpass = '*****';		$dbname = '*****';		$username = $_POST['username'];		$password = $_POST['password'];				$conn = mysql_connect($dbhost,$dbuser,$dbpass)			or die ('Error connecting to mysql');		mysql_select_db($dbname);		$query = sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s') AND password='%s'",			mysql_real_escape_string($username),			mysql_real_escape_string(md5($password)));		$result = mysql_query($query);		list($count) = mysql_fetch_row($result);		if($count == 1) {		session_start();			$_SESSION['authenticated'] = true;			$_SESSION['username'] = $username;			$query = sprintf("UPDATE users SET last_login = NOW() WHERE UPPER(username) = UPPER('%s') AND password = '%s'",				mysql_real_escape_string($username),				mysql_real_escape_string(md5($password)));			mysql_query($query);			$query = sprintf("SELECT is_admin FROM users WHERE UPPER(username) = UPPER('%s') AND password='%s'",				mysql_real_escape_string($username),				mysql_real_escape_string(md5($password)));			$result = mysql_query($query);			list($is_admin) = mysql_fetch_row($result);			if($is_admin == 1) {				header('Location:admin.php');						} else {				header('Location:game.php');							}		} else {	?><span style='color:red'>Error: that username and password combination does not match any currently within our database.</span><?php	}	}?><form action='login.php' method='post'>Username: <input type='text' name='username' /><br />Password: <input type='password' name='password' /><br /><input type='submit' value='Login' /></form>

Link to comment
Share on other sites

Is that your whole problem or do you have any body or head tags above the code?if yes, this will return cannot modify header informationIs your script included in another one under the body or head tags? if yes, this will return cannot modify header informationDo you have a line above your php code tags thats empty? if yes, this will return cannot modify header informationAnd i thought session is out of use?Ive never been able to use sessions latly, only cookies.. someone out there who can answer this?Hope something of this helps :)

Link to comment
Share on other sites

session_start() must come immediately after the opening PHP tags, and there mustn't be anything else before the first opening PHP tag for it to work. 1: <?php2: session_start();

Link to comment
Share on other sites

Now I only get this error message and all i have on line 21 is the session start. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home1/suitefou/public_html/opxtest/web/login.php:9) in /home1/suitefou/public_html/opxtest/web/login.php on line 21Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home1/suitefou/public_html/opxtest/web/login.php:9) in /home1/suitefou/public_html/opxtest/web/login.php on line 21

Link to comment
Share on other sites

That's what I told you - session_start() must be line 1 or two of any document it's in. Either on the same or the next line as <?php

Link to comment
Share on other sites

Not necessarily the first line; just before any output. session_start() sets a header, and headers (obviously) have to come before the response-body.

Link to comment
Share on other sites

That's what I told you - session_start() must be line 1 or two of any document it's in. Either on the same or the next line as <?php
line 1 at the start of the PHP tags?
Link to comment
Share on other sites

Dude, seriously, this isn't hard. Start your page:<?php session_start();then follow it with whatever else you have on the page. There should be nothing before that, no whitespace, nada. As Synook pointed out, it doesn't actually need to be the first thing on the page, but it keeps it out of trouble up there.Edit: apologies for being an a*hole ^

Edited by chibineku
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...