I've had this site running for quite some time error free. The host must have upgraded something and now my site's authenticating processes don't work. I've traced the problem to where I set some cookies as they aren't appearing as set when I retrieve them from another page. Here is the code where I set the cookies:
<?PHP
//Connecting to database
include ("connectDB.php");
//if ($Submit){
//Collect Form Data
$username = $_POST['username'];
$passWord = $_POST['passWord'];
$save = $_POST['save'];
//print "User: $username, Pass: $passWord, and Saved: $save";
if ($username != "" && $passWord != ""){
function login($username, $passWord) {
$conn = db_connect();
$result = mysql_query("SELECT * FROM loginusers WHERE users='".$username."' AND password='".$passWord."'");
if(mysql_num_rows($result)<1) {
// if query error
setcookie("error", "Incorrect login attempt, please try again." );
Header("Location: index.php");
}
if(mysql_num_rows($result)>0) {
// if the values match values in the database
return("true");
}
mysql_close();
}
// now check the values received via the form
$result = login($username, $passWord);
if($result == "true") {
// set //
if($save == "Yes"){
setcookie("siteuser", $username, time() + 60*60*24*30);
setcookie("passcode", $passWord, time() + 60*60*24*30);
setcookie("save", Yes, time() + 60*60*24*30 );
setcookie("error", "", time()-3600);
}else{
setcookie("siteuser", $username );
setcookie("passcode", $passWord );
setcookie("error", "", time()-3600);
}
// redirect //
Header("Location: home.php");
}
}
else {
Header("Location: login.php");
setcookie("error", "Incorrect login attempt, please try again." );
}
//}
?>
And here is the page code that I use to retrieve the cookies:
<?PHP
if ($siteuser == "" || $passcode == "") {
echo "<script language='javascript'>self.location='index.php';</script>";
//Header("Location: index.php");
}
?>
If you see anything thats off or is not allowable anymore please let me know. I don't keep up on the latest coding as I'm a web designer.
Thanks!