yeah, that's ok, but I would add to that. I use a similar idea on my website.
What I do is I store the user id, the administration level id, password, and the date they logged in a cookie.
now, the password is md5 encryped so nobody can read it.
on top of this I use just one cookie to store everything and encode all the data using base64_encode() for extra security.
<?
$cookieData = base64_encode("$iMemberID;$sMemberNameName;$sMemberPassword;$dtMemberLastLogin");
return setcookie("cSession", $cookieData, time()+$iSessionLength);
?>
It's not unbreakable, but nobody is going to be able to read any of that data in a hurry and certainly not the password.
now, when I need to authenticate somebody for a page, I just check the cookie like so:
<?
if(isset($_COOKIE["cSession"])){
$this->cSession = $_COOKIE["cSession"];
$cSession = base64_decode($this->cSession);
$cSession = explode(";", $this->cSession);
$sIDValue = $this->cSession[0];
$sNameValue = $this->cSession[1];
$sPasswordValue = $this->cSession[2];
$sDateLastLoginValue = $this->cSession[3];
}
?>
and then check the username and password variables against the database.
So, I got this idea from reading some of the source code to phpNuke portal system. I thought it was a good idea an applied the concept to my website. I prefer cookies to using sessions, I've never used sessions on anything. Pretty much a session is a cookie, but you don't have as much flexability... so.. you may as well just use a cookie. It's not anymore code, really...
well, hope that helps
-Adam 🙂