I get the following error when I login...
Then below that I get the same but on line 263 and line 265.Warning: Cannot modify header information - headers already sent by (output started at /home/a4334033/public_html/project/login.php:6) in /home/a4334033/public_html/project/login.php on line 262
Below is the code for my login.php...
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Mini-Antiques > Login</title>
<style type='text/css'>
* html{
margin: 0;
padding: 0;
border: 0;
}
body {
background-color: #000000;
}
#container {
margin: 0 auto;
width: 800px;
}
#hcontainer {
margin: 0 auto;
width: 800px;
}
#header {
width: 800px;
height: 254px;
background-image: url(images/w_header.png);
background-repeat: no-repeat;
}
#mcontainer {
margin: 0 auto;
width: 560px;
background-color: #ba9f6d;
}
#main {
width: 550px;
height: auto;
margin: 0 auto;
background-color: #ba9f6d;
color: #000000;
font-family: helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
}
#nav {
width: 800px;
height: 48px;
background-image: url(images/w_nav.png);
background-repeat: no-repeat;
font-family: helvetica, sans-serif;
font-size: 14px;
font-weight: 900;
color: #000000;
text-align: center;
padding-top: 6px;
}
#fcontainer {
margin: 0 auto;
width: 800px;
}
#footer {
width: 800px;
height: 68px;
color: #000000;
background-image: url(images/w_footer.png);
background-repeat: no-repeat;
padding-top: 8px;
text-align: center;
font-family: helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
}
h1 {
font-size: 25px;
font-family: "tebuchet ms", sans-serif;
font-weight: 900;
color: #4679aa;
}
a:link {
color: #ffffff;
font-family: helvetica, sans-serif;
font-weight: bold;
font-size: 14px;
}
a:visited {
color: #ffffff;
font-family: helvetica, sans-serif;
font-weight: bold;
font-size: 14px;
}
a:hover {
color: #ffffff;
font-family: helvetica, sans-serif;
font-weight: bold;
font-size: 14px;
}
a:active {
color: #ffffff;
font-family: helvetica, sans-serif;
font-weight: bold;
font-size: 14px;
}
.name {
font: 11px Verdana, Arial, Helvetica, sans-serif;
color: #000000;
font-weight: 900;
}
.textfield {
font-size: 11px;
color: #ffffff;
background-color: #333333;
border: 1px solid #555555;
}
</style>
</head>
<body>
<div id='container'>
<div id='header'></div>
<?php include'nav.php'; ?>
<div id='main'>
<?php
/*
* login.php
* ---------------------
* Description:
* This file logs the user in and creates a session in the database.
*
*/
include 'global.php';
$username = mysql_real_escape_string( trim($_POST['username']) );
$password = mysql_real_escape_string( $_POST['password'] );
$submit = $_POST['submit'];
if( isset( $_COOKIE['session_id'] ) || isset ( $_COOKIE['user_id'] ) ){
// Already logged in so cancel script.
$safeSessionId = mysql_real_escape_string( $_COOKIE['session_id'] );
$query = mysql_query("SELECT * FROM sessions WHERE session_id='$safeSessionId'");
$data = mysql_fetch_array( $query );
if($data['session_id'] == ''){
// Session Doesn't Exist
setcookie('session_id','',time()-3600,'');
setcookie('user_id','',time()-3600,'/');
} else {
//User Is Already Logged In. Kill Script.
echo 'You are alreay logged in.';
return;
}
}
if( isset( $submit ) ){
// The user submitted the login form
if( $username == '' ){
// Username Field is Blank
$error[0] = 'Username Field Is Blank';
echo $username;
} else {
$query = mysql_query("SELECT * FROM members WHERE username='$username'");
$data = mysql_fetch_array($query);
if( $data['id'] == '' ){
$error['top'] = 'Username and/or password do not match.';
} else {
$error['top'] = '';
$error[0] = FALSE;
}
}
if( $password == '' ){
// Password Field Was Blank
$error[1] = 'Password Field Is Blank';
} else {
$MD5password = md5( $password );
$query = mysql_query("SELECT * FROM members WHERE username='$username'");
$data = mysql_fetch_array($query);
if( $data['password'] == $MD5password ){
$error[1] = FALSE;
$user_id = $data['id'];
} else {
$error['top'] = 'Username and/or password do not match.';
$error[1] = '-';
}
}
if( $error[0] == '' && $error[1] == ''){
// Everything is alright
$session_id = mt_rand();
$loop = TRUE;
$timeStamp = time();
$location = 'Loggin In';
// Makes sure there aren't duplicate session ids
$query = mysql_query("SELECT * FROM sessions WHERE session_id='$session_id'");
$data = mysql_fetch_array($query);
if($data['id'] == ''){
$loop = false;
}
while($loop){
$session_id = mt_rand();
$query = mysql_query("SELECT * FROM sessions WHERE session_id='$session_id'");
$data = mysql_fetch_array($query);
if($data['id'] == ''){
$loop = false;
}
}
// Create Session
mysql_query("INSERT INTO sessions
(session_id,time,user_id,location)
values
('$session_id','$timeStamp','$user_id','$location')");
setcookie('session_id',$session_id,time() + $TimeOutFormula,'/');
setcookie('user_id',$user_id,time() + $TimeOutFormula,'/');
header('Location: '.$LandingPage);
return; // Kills script so login form wont show up.
} else {
// Something went wrong
}
} else {
// The user has not submitted the login form
}
?>
<form action="" method="POST">
<?php echo $error['top'] ?>
<table align='center'>
<tr>
<td class='name'> Username </td>
<td class='textfield'> <input type="text" name="username" value="<?php echo $_POST['username'] ?>"><?php echo $error[0] ?></td>
</tr>
<tr>
<td class='name'> Password </td>
<td class='textfield'> <input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2"> <input name="submit" type="submit" value="Login"> </td>
</tr>
</table>
</form><br />
</div>
<div id='footer'></div>
</div>
</body>
</html>It would be great if anyone could help me on this.