login problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

login problem

Post 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.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post 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.
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post 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!
Post Reply