I am making 2 cookies, but when they are set, it shows me this error
"Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\forum\index.php:4) in C:\xampp\htdocs\forum\index.php on line 81"
But I dont have any headers??
Here is the code
$expire=time()+60*60*24*30;
setcookie('username',$u,$expire);
setcookie('password',$p,$expire);
I made a login script, with a remember me feature
Here is the entire script
<?
session_start();
include("global.php");
echo "<link href='style.css' rel='stylesheet' type='text/css' />";
?>
<script type="text/javascript">
<!--
function logconfirm(){
var f = confirm("Are You Sure You Want To Logout?");
if(f){
return true;
}
else{
return false;
}
}
//-->
</script>
<title>Main Forums Page</title>
<div id="page">
<?
if($_SESSION['username']){
echo "<div id='user_info'>";
echo "<h6>Welcome ".$_SESSION['username']."!";
$result = mysql_query("SELECT `admin` FROM `users` WHERE `username` = '".$_SESSION['username']."'");
while($row = mysql_fetch_array($result)){
if($row['admin'] == 1){
echo "<br><a href='new_cat.php'>New Catagory</a>";
}
}
// set timeout period in seconds
$inactive = 900;
// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive)
{
// go to login page when idle
session_unset();
session_destroy();
}
}
echo "<br>\n<a href='search.php'>Search Users</a><br>\n<a href='users.php'>Total Users</a><br>\n<a href='inbox.php'>Inbox</a><br>\n<a href='userchange.php'>Edit User Info</a>\n";
echo "<br>\n<a href='logout.php' onClick='return logconfirm()'>logout</a></h6>";
echo "</div>";
echo "<div id='page2'>\n";
echo "<h2>Categories</h2>\n";
echo "<hr size='1' width='75%'>\n";
$result0 = mysql_query("SELECT * FROM forum_cats ORDER BY date");
while($row = mysql_fetch_array($result0)){
echo "<a href='forums.php?id=".$row['id']."'>".$row['cat_name']."</a><br>Date Added: ".$row['date']."<hr size='1' width='50%'><br>\n";
}
echo "<br>\n";
echo "</div>";
}else{
echo "Welcome Guest! Please login or register to start viewing the categories, topics, and to start posting!<br>\n
<a href='register.php'>Register Here</a>";
$c1 = $_COOKIE["username"];
$c2 = $_COOKIE["password"];
?>
<br><br>
<table border=0 align='center'>
<form action='./index.php' method='post'>
<tr><td colspan="3" align="center" bgcolor="#333333"><font color="#ffffff">Login Form</font></td></tr>
<tr><td>Username:</td><td colspan='2'><input type=text name=user maxlength=20 value='<?php echo $c1; ?>'></td></tr>
<tr><td>Password:</td><td colspan='2'><input type=password name=pass maxlength=20 value='<?php echo $c2; ?>'></td></tr>
<tr><td align='left'>Remember </td><td align='center'><input type='checkbox' value='1' name='remember'></td><td align='right'><input type="submit" value="Login" name="submit2"/></td></tr>
</form>
</table>
<?
$rem = $_POST['remember'];
$sub = $_POST['submit2'];
$u = $_POST['user'];
$p = $_POST['pass'];
if($sub){
if($rem == 1){
$expire=time()+60*60*24*30;
setcookie('username',$u,$expire);
setcookie('password',$p,$expire);
}
$sql = mysql_query("SELECT count(id) FROM users WHERE username='$u' AND password='$p'");
$result = mysql_result($sql, 0);
if($result!=1){
print "<br>Invalid Login Information";
}else{
$result1 = mysql_query("SELECT * FROM users");
while($row = mysql_fetch_array($result1)){
mysql_query("UPDATE users SET admin = '1' WHERE id = '1'") or die(mysql_error());
}
$_SESSION['username'] = $u;
$_SESSION['timeout'] = time();
mysql_query("UPDATE `users` SET `online` = 'Online' WHERE `username` = '".$_SESSION['username']."'") or die(mysql_error());
echo "<br>You are now logged in ".$_SESSION['username']."!";
}
}
}
?>