RE: Remember and Cookies
I've found it convenient to encapsulate cookie functions into an object.
It worked last time I checked although I've been thinking about moving the
digest, AKA secret-salt, into the cookie_jar as a function $this->
getDigest();
so that everything stays in sync.
If I remember correctly, there can be problems with cookies on Windows.
Something related to domains, especially on private networks with no DNS.
Cookies are only available with certain URLs (specified when you set the
cookie).
If your local network is using IP addresses instead of domain names,
nasty problems may arise.
cheers,
pat
<?php
class cookie_jar
{
private $_cookie_name;
private $_cookie_contents;
private $_db_cookie;
private $_cookie_expire;
private $_user_name;
private $_success = false;
function __construct ($name)
{
$this->_cookie_name = $name;
}
function get_cookie_name ()
{
return $this->_cookie_name;
}
function get_name()
{
return $this->_user_name;
}
function set_expire($expire)
{
$this->_cookie_expire = $expire;
}
function get_db_cookie()
{
return $this->_db_cookie;
}
function get_contents()
{
return $this->_cookie_contents;
}
function get_cookie()
{
if(isset($_COOKIE[$this->_cookie_name])){
$this->_cookie_contents = $_COOKIE[$this->_cookie_name];
list($username, $cookie) = explode("+",$this->_cookie_contents);
$this->_user_name = $username;
$this->_db_cookie = $cookie;
$this->_cookie_expire = $cookie;
$this->_success = true;
}
}
function set_cookie()
{
setcookie($this->_cookie_name,$this->_cookie_contents ,
$this->_cookie_expire,"/",false,0);
}
function unset_cookie()
{
setcookie($this->_cookie_name,'', time()-42000,"/",false,0);
}
function make_cookie($name, $pass, $digest)
{
$this->_user_name = $name;
$this->_db_cookie = md5("$pass" . "$digest" );
$this->_cookie_contents = implode("+", array($this->_user_name,
$this->_db_cookie));
}
}
?>