jeffry
01-24-2007, 11:56 AM
I am getting the below mentioned errors when i perform the login by giving correct password and username
Warning : Cannot send session cookie-headers already sent by(output started at /var/www/html/BNBU/weblogin.php:13) in /var/www/html/BNBU/weblogin. on line 87
Warning : cannot send session cache limiter-headers already sent by(output started at /var/www/html/BNBU/weblogin.php:13) in /var/www/html/BNBU/weblogin. on line 87
Warning : Cannot add header information- headers already sent by(output started at /var/www/html/BNBU/weblogin.php:13) in /var/www/html/BNBU/weblogin. on line 87
My loginform code is 'weblogin.php'
Here I have a table in mysql named webadmin (username,password)
<html>
<head>
<title>Webmaster Login Form</title>
</head>
<body>
<br>
<br>
<br>
<br>
<form action="weblogin.php" method="post">
<table width=225 border=0 align="center">
<tr>
<td width="219" bgcolor="#999999">
<p align="center"><font color="white"><span style="font-size:12pt;"><b>LOGIN</b></span></font></p>
</td>
</tr>
<tr>
<td width="219">
<table width=220 border=0 align="center">
<tr>
<span style="font-size:10pt;"><b>Username:</b></span>
<input type="text" name="username"/>
</tr>
<tr>
<span style="font-size:10pt;"><b>Password: </b></span>
<input type="password" name="password"/>
</tr>
<tr>
<span style="font-size:12pt;"><b><a href="forgot.html" target="_blank">Forgot Password</a></b></span>
<input type="submit" name="submit" value="Login" onMouseOver =" this.style.background='lemonchiffon';this.style.color='brown';" onMouseOut =" this.style.background='#78B4FF';this.style.color='darkblue';"/>
<input type="hidden" name="submitted" value="TRUE" />
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
// Check if the form has been submitted.
if (isset($_POST['submitted']))
{
mysql_connect("localhost","root") or die("Error in Connection:".mysql_error());
mysql_select_db("BNBU") or die(mysql_error()); // Connect to the db.
$errors = array(); // Initialize error array.
// Check for an username.
if (empty($_POST['username']))
{
$errors[] = 'Enter your username.';
echo "<br>";
}
else
{
$e = $_POST['username'];
}
// Check for a password.
if (empty($_POST['password']))
{
$errors[] = 'Enter your password.';
echo "<br>";
}
else
{
$p = $_POST['password'];
}
if (empty($errors))
{
// If everything's OK.
// Retrieve the username and password for that username/password combination.
$query = "SELECT username,password FROM webadmin WHERE username='$e' AND password='$p'";
$result = mysql_query ($query); // Run the query.
$row = mysql_fetch_array($result); // Return a record, if applicable.
if ($row)
{
// A record was pulled from the database.
// Set the session data & redirect.
session_start();
$_SESSION['username'] = $row[0];
$_SESSION['password'] = $row[1];
// Redirect the user to the loggedin.php page.
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') )
{
$url = substr ($url, 0, -1); // Chop off the slash.
}
// Add the page.
$url .= '/adminpage.html';
header("Location: $url");
exit(); // Quit the script.
}
else
{ // No record matched the query.
$errors[] = 'The username and password entered do not match.'; // Public message.
//$errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.
}
} // End of if (empty($errors)) IF.
mysql_close(); // Close the database connection.
} else { // Form has not been submitted.
$errors = NULL;
} // End of the main Submit conditional.
// Begin the page now.
if (!empty($errors))
{
// Print any error messages.
echo '<b>Error!</b><br/>';
foreach ($errors as $msg)
{
// Print each error.
echo " - $msg<br />\n";
}
echo '<p>Please try again.</p>';
}
?>
Warning : Cannot send session cookie-headers already sent by(output started at /var/www/html/BNBU/weblogin.php:13) in /var/www/html/BNBU/weblogin. on line 87
Warning : cannot send session cache limiter-headers already sent by(output started at /var/www/html/BNBU/weblogin.php:13) in /var/www/html/BNBU/weblogin. on line 87
Warning : Cannot add header information- headers already sent by(output started at /var/www/html/BNBU/weblogin.php:13) in /var/www/html/BNBU/weblogin. on line 87
My loginform code is 'weblogin.php'
Here I have a table in mysql named webadmin (username,password)
<html>
<head>
<title>Webmaster Login Form</title>
</head>
<body>
<br>
<br>
<br>
<br>
<form action="weblogin.php" method="post">
<table width=225 border=0 align="center">
<tr>
<td width="219" bgcolor="#999999">
<p align="center"><font color="white"><span style="font-size:12pt;"><b>LOGIN</b></span></font></p>
</td>
</tr>
<tr>
<td width="219">
<table width=220 border=0 align="center">
<tr>
<span style="font-size:10pt;"><b>Username:</b></span>
<input type="text" name="username"/>
</tr>
<tr>
<span style="font-size:10pt;"><b>Password: </b></span>
<input type="password" name="password"/>
</tr>
<tr>
<span style="font-size:12pt;"><b><a href="forgot.html" target="_blank">Forgot Password</a></b></span>
<input type="submit" name="submit" value="Login" onMouseOver =" this.style.background='lemonchiffon';this.style.color='brown';" onMouseOut =" this.style.background='#78B4FF';this.style.color='darkblue';"/>
<input type="hidden" name="submitted" value="TRUE" />
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
// Check if the form has been submitted.
if (isset($_POST['submitted']))
{
mysql_connect("localhost","root") or die("Error in Connection:".mysql_error());
mysql_select_db("BNBU") or die(mysql_error()); // Connect to the db.
$errors = array(); // Initialize error array.
// Check for an username.
if (empty($_POST['username']))
{
$errors[] = 'Enter your username.';
echo "<br>";
}
else
{
$e = $_POST['username'];
}
// Check for a password.
if (empty($_POST['password']))
{
$errors[] = 'Enter your password.';
echo "<br>";
}
else
{
$p = $_POST['password'];
}
if (empty($errors))
{
// If everything's OK.
// Retrieve the username and password for that username/password combination.
$query = "SELECT username,password FROM webadmin WHERE username='$e' AND password='$p'";
$result = mysql_query ($query); // Run the query.
$row = mysql_fetch_array($result); // Return a record, if applicable.
if ($row)
{
// A record was pulled from the database.
// Set the session data & redirect.
session_start();
$_SESSION['username'] = $row[0];
$_SESSION['password'] = $row[1];
// Redirect the user to the loggedin.php page.
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') )
{
$url = substr ($url, 0, -1); // Chop off the slash.
}
// Add the page.
$url .= '/adminpage.html';
header("Location: $url");
exit(); // Quit the script.
}
else
{ // No record matched the query.
$errors[] = 'The username and password entered do not match.'; // Public message.
//$errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.
}
} // End of if (empty($errors)) IF.
mysql_close(); // Close the database connection.
} else { // Form has not been submitted.
$errors = NULL;
} // End of the main Submit conditional.
// Begin the page now.
if (!empty($errors))
{
// Print any error messages.
echo '<b>Error!</b><br/>';
foreach ($errors as $msg)
{
// Print each error.
echo " - $msg<br />\n";
}
echo '<p>Please try again.</p>';
}
?>