Forum Moderators: coopster
setcookie("ck_user", $user);
setcookie("ck_pass", $pass);
header("Location: /main.php");
exit;
This cookie will only be valid for the session since I didn't set a time on it, correct?
Now on main.php, I want it to check for the cookies and if they are not there I want to redirect them to the login page, and if the cookie is there I want it to execute the main.php page. How do I go about doing this?
Thanks a bunch!
One thing that comes to mind first is you are setting two cookies for one site, bad plan. I have had a lot of trouble when people have used this method. You are better off setting one single cookie with all the info in it.
Take a look at serialize()
[php.net...]
this will provide you a way to put multiple values in there.
here is a little auth lib I used somewhere at sometime, it was a while ago but it worked well. I also didn't write this particular one, someone who worked for me did.
define (AUTH_HASH, $REMOTE_ADDR.$HTTP_USER_AGENT);
function auth_login($username) {
if (!empty($username)) {
$out_auth = serialize(array($username,md5($username.AUTH_HASH)));
setcookie('auth', $out_auth, 0, '/', '', 0);
}
}
function auth_verify() {
global $auth, $username;
list($username, $auth) = unserialize($auth);
$test_auth = md5($username.AUTH_HASH);
if ($auth == $test_auth)
return 1;
else
return 0;
}
function auth_logout() {
setcookie('auth', '', -1, '/', '', 0);
}
Does anyone know if others already have these features rolled into one package beyond what PHPBuilder supplies?