I have a feeling that I'm getting an error because my cookies need to be set immediately at the top of the page, but I'm not sure how to fix this because I'm using an include file to set my cookies. The error comes when clicking the "remember me" checkbox:
Warning: Cannot modify header information - headers already sent by- (lines 59-61 on my login_script.inc.php page).
So, here is the header for my login.php page:
<?php session_start(); ?>
<?php include('includes/scripts/login_script.inc.php');?>
<?php include('includes/scripts/pagetitle.inc.php');?>
<!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>
<title>so.did.we <?php if (isset($pagetitle)) echo "| {$pagetitle}"; ?> - where strangers become friends</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="Description" content="Welcome to so.did.we - where strangers become friends" />
<meta name="Keywords" content="welcome, landing page, sodidwe, so.did.we, social networking, friends, connections, profile, community, events, event calendar, calendar, matching, matches, interactive, daily organizer, schedule, organize, interests, groups, dating, business, sports, politics, work, jobs" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/calendarstyle.css" type="text/css" />
<link rel="shortcut icon" href="images/sodidwe4.ico" />
</head>
And, here is my included login_script.inc.php
Getting errors on the 4 lines where my cookies are:
<?php
//***********THIS FILE MUST GO ABOVE HEADER*****************
//If username is not blank, then check database
if (isset($_POST['username'])) {
include_once "includes/scripts/connect_to_mysql.php";
$username = $_POST['username'];
$password = $_POST['password'];
$rememberme = $_POST['rememberme']; // Added for the remember me feature
$username = mysql_real_escape_string($username);
$rememberme = mysql_real_escape_string($rememberme);
// Add MD5 Hash to the password variable
$password = md5($password);
//looks in database where there is a username & password and the account has been activated
$sql = mysql_query("SELECT * FROM member_profile WHERE username='$username' AND password='$password' AND email_activated='1'");
$login_check = mysql_num_rows($sql);
//if the database check is good, it creates Sessions
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$user_id = $row["user_id"];
$_SESSION['user_id'] = $user_id;
$firstname = $row["firstname"];
$_SESSION['firstname'] = $firstname;
$lastname = $row["lastname"];
$_SESSION['lastname'] = $lastname;
$username = $row["username"];
$_SESSION['username'] = $username;
mysql_query("UPDATE member_profile SET last_log_date=now() WHERE user_id='$user_id'");
} // close while
// Remember Me Section Addition... if member has chosen to be remembered in the system
if($rememberme == "yes"){
setcookie("idCookie", $user_id, time()+2592000, "/", ".sodidwe.com"); // 30 days; 24 hours; 60 mins; 60secs
setcookie("firstnameCookie", $firstname, time()+2592000, "/", ".sodidwe.com"); // 60 days; 24 hours; 60 mins; 60secs
setcookie("userCookie", $username, time()+2592000, "/", ".sodidwe.com"); // 60 days; 24 hours; 60 mins; 60secs
setcookie("passCookie", $password, time()+2592000, "/", ".sodidwe.com"); // 60 days; 24 hours; 60 mins; 60secs
}
$msgToUser = "<h2>Welcome Back, $firstname!</h2>
<p class=\"content\">You are Logged In, check out your matching events to see if anyone else has entered new events that are the same as yours!" ;
include_once 'user_message.php';
exit ();
} else {
//VALIDATIONS
if($login_check == 0){
$errorLogin = "Your Login information is not correct.";
}
} //CLOSE ELSE
}// CLOSES IF FORM IS SUBMITTED
?>