I have the following page code for a login page:
<?php
// Set the page title and include the HTML header.
$page_title = ‘Reidsville Christian Church – Member Login’;
//include (‘./template.inc’);
?>
<link href=”member.css” rel=”stylesheet” type=”text/css”>
<div id=”main>
<div id=”main-content”>
<?php
if (isset($_POST[‘submit’])) { // Handle the form.
$message = NULL; // Create an empty new variable.
// Check for a username.
if (empty($_POST[‘username’])) {
$u = FALSE;
$message .= ‘<p>You forgot to enter your username!</p>’;
} else {
$u = $_POST[‘username’];
}
if (empty($_POST[‘password’])) {
$p = FALSE;
$message .= ‘<p>You forgot to enter your username!</p>’;
}else
{
$p = $_POST[‘password’];
}
if ($u && $p) //if everything is ok
{
require_once(‘./mysql_connect.php’);
$query = “SELECT username,fname FROM members WHERE username = ‘$u’ AND
password = ‘$p'”;
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_BOTH);
if ($row)
{
//set a cookie & redirect
setcookie(‘first_name’,$row[‘fname’]);
setcookie(‘user_id’, $row[‘username’]);
$message = ‘<p>User Found in db</p>’;
echo ‘<font color=”red”>’, $message, ‘</font>’;
exit();
}else
{
$message = ‘<p>The username and password entered do not match those on file!.</p>’;
}
mysql_close(); //close the database connection.
}else
{
$message .= ‘<p>Please try again.</p>’;
}
}
// Print the message if there is one.
if (isset($message)) {
echo ‘<font color=”red”>’, $message, ‘</font>’;
}
?>
<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post”>
<div id=”divlogin”>
<fieldset><legend>Enter your information in the form below:</legend>
<p> <b>User Name:</b> <input type=”text” name=”username” size=”10″ maxlength=”20″ value=”<?php if (isset($_POST[‘username’])) echo $
<p><b>Password:</b> <input type=”password” name=”password” size=”20″ maxlength=”20″ value=”” />
</fieldset>
<div align=”center”><input type=”submit” name=”submit” value=”Register” /></div>
</div>
</form><!– End of Form –>
</div>
</div>
It works fine but when the page logs me in I get these results and I don’t understand what they mean:
Warning: Cannot modify header information – headers already sent by (output started at /hsphere/local/home/rutledj/rcc.cooltoneamps.com/memberlogin.php:2) in /hsphere/local/home/rutledj/rcc.cooltoneamps.com/memberlogin.php on line 49
Warning: Cannot modify header information – headers already sent by (output started at /hsphere/local/home/rutledj/rcc.cooltoneamps.com/memberlogin.php:2) in /hsphere/local/home/rutledj/rcc.cooltoneamps.com/memberlogin.php on line 50
User Found in db
Any suggestions?
Thanks,
Rut
Just realized that it is the setcookie code causing the problem. Am I only allowed to do this once?