/    Sign up×
Community /Pin to ProfileBookmark

question about these results

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 $_POST[‘username’]; ?>” /></p>

<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?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@deep_dhyaniDec 02.2005 — You have to define cookie before echo becuse cookie is part of header and you can't send any output before header information.
×

Success!

Help @rutledj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...