I am trying to use sessions in my PHP. . .also trying to use headers in my PHP and neither are working. Here is the code I am using, once a user has been authenticated, to register them as an authenticated user and direct them to my main page.

session_start();
$user = "$user";
session_register("user");
header("location: main.php");

Here is the error message I am getting when the login page is executed.

Warning: Cannot send session cookie - headers already sent by (output started at do_login.php:8) in do_login.php on line 33

Warning: Cannot send session cache limiter - headers already sent (output started at do_login.php:8) in do_login.php on line 33

Warning: Cannot add header information - headers already sent by (output started at do_login.php:8) in do_login.php on line 37

==============================================

This is all my PHP code for the login.php page.

<?php 

//connect to mysql
$db = mysql_connect'customerdb.nuvox.net', 'tsppadm', 'fdVyrikD') or die("Failed to connect");
	if(!$db){
		echo 'Cannot connect to database';
		exit;
	}//if

$db = mysql_select_db('www_tsppumps_com');
if(!db){
	echo 'Cannot select database';
	exit;
}//if

//query the database to see if there is a user which matches user/pass
$query = "SELECT count( * ) FROM users_db WHERE user='$user' AND pass='$pass'";
$result = mysql_query($query) or die ("Could not query database.");
$count = mysql_result($result, 0, 0);

if($count > 0){
	//user is authenticated
	print "<br>";
	print "<br>";
	//start session
	session_start();
	$user = "$user";
	session_register("user");

	header("location: main.php");
	print "<font size='5' face='Book Antiqua'><a href='/main.php'>Click here to direct you to our main page.</a></font>";
	//header("Location:[url]http://www.tsppumps.com/main.php[/url]");
	exit;
}//if

else{
	//user not authenicated
	echo 'User authentication required!  Please try again.';
	echo "<br>";
	echo "<br>";
	print "<font size='5' face='Book Antiqua'><a href='javascript:history.back()'>Go Back</a></font>";
}//else

?>

Thanks for your help!!!

r2

    One more thing you might should know. . .it gives me those error messages no matter where the php code is placed in the document. By that I mean if the session is started at the begining, middle, or end of my php code.

      I figured it out. I had read all the posts about there being a blank line at the top of my php document which would cause this error. There were no blank lines but apparently Dreamweaver MX adds a line automatically at the top which does not have to be there.

      Sorry for the long post!

      r2

        Write a Reply...