Hey guys. I am trying to use set_cookie to put a cookie on the users computer so that they can log in to the password protected areas of my site and download certain files.
Sessions wont work with this because it involves numerous popup windows and since sessions dont carry over across multiple browser instances then it wont work.
I am not sure if the cookie is even being created..I cant find it on my computer doing a search, but then again I am not sure where to look exactly on winxp pro.
Here is the code I am using to set the cookie.
<?php
// Login Script
// Created By Lee hasley
If (!isset ($_POST['Login'])) {
header("Location: login.php");
exit();
}else{
$Username=$_POST['txtUsername'];
$Password=$_POST['txtPassword'];
$status = auth_user($Username, $Password);
If (!$status) {
header("Location: login.php?msg=Incorrect Username, Password Combination");
exit();
} else {
setcookie("CookieName", "logged in", time()+3600 * 24, "/");
header ("Location: loggedin.php");
}
}
function auth_user($Username, $Password)
{
if ($Username != "wer" && $Password != "wer"){
return 0;
}else {
return 1;
}
}
?>
Then I check to see if it exists on this page
<?php
// checklogin.php
// checks to see if user is logged in
if (!isset($_COOKIE['CookieName']))
{
// if session check fails, invoke error handler
header("Location: login.php");
exit();
}
else
{
header("Cache-Control: no-cache, must re-validate");
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
$URL = "http://www.mysite.com".$_GET['URL'];
header("Location: $URL");
}
?>
Now i am not sure if the cookie is not being created or if my checking for it is not working..but either way it is redirecting me to the login page when I have already logged in.
Anyone know what I am doing wrong?