Page 1 of 1

login problem

Posted: Wed Sep 13, 2006 9:59 am
by speedy33417
I have two pages index.php takes the login information and loggedin.php makes the form variables global session variables, and for now just echoing it to see if it works. Well, I'm getting an error message:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /var/www/html/loggedin.php:2) in /var/www/html/loggedin.php on line 3

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/www/html/loggedin.php:2) in /var/www/html/loggedin.php on line 3

Here's my code:

index.php

Code: Select all

<form method="post" action="loggedin.php">
	<div align="center">
		<table border="0" width="610" cellpadding="0" cellspacing="0">
			<tr>
				<td width="105" valign="top"><span class="text1">&nbsp;user ID</span></td>
				<td width="105" valign="top"><span class="text1">&nbsp;password</span></td>
				<td width="400"></td>
			</tr>
			<tr>
				<td width="105" valign="top"><input name="userId" class="form3"></td>
				<td width="105" valign="top"><input name="passWord" class="form3"></td>
				<td width="400"><input type="submit" value="Log in"></td>
			</tr>
		</table>
	</div>
</form>
loggedin.php

Code: Select all

<?php
session_start();
$userId = $_POST['userId']; 
$passWord = $_POST['passWord']; 

$_SESSION['userId'] = $userId; 
$_SESSION['passWord'] = $passWord;  

echo $_SESSION['userId'];
echo $_SESSION['passWord']
?>
Any idea why I'm getting that error message?

Thanks.

Posted: Wed Sep 13, 2006 10:08 am
by GM
Check that you've got no whitespace before the first <?php tag in loggedin.php

Even if there is a single space or newline character before it, php sends all the headers, and session_start() won't work any more.

Posted: Wed Sep 13, 2006 11:13 am
by speedy33417
You're the man! There was empty line 1, and my code started on line 2. I never would have figured out that it could be a problem...

Thanks a lot!