Is this a good way to store multiple values in a cookie?
Posted: Sat Sep 26, 2009 9:05 pm
Hello,
I have a login script, when the user logs in a cookie is created with email ID encrypted. If cookie cant be created then a session is created to store the information. I have two types of user in my site. So along with encrypted email id, i also want to store the information about the type of user. Here is what I am doing. Please let me know is this good? or is there any other better way?
Here is how I am trying to retrieve the values for the $cookie_data
I dint try this yet, so I have no idea if this will really work but first i would like to know if this is a good way to do what I am trying to do.
Thank you,
I have a login script, when the user logs in a cookie is created with email ID encrypted. If cookie cant be created then a session is created to store the information. I have two types of user in my site. So along with encrypted email id, i also want to store the information about the type of user. Here is what I am doing. Please let me know is this good? or is there any other better way?
Code: Select all
// Create cookie and store login information
$cookie_name = "userlogin"; // Cookie name
$loginkey = md5($email); // Encrypted login key
$userType = "candidate"; // User type
$cookie_data = $loginkey."+|+".$userType; // Cookie data
$cookie_time = time()+60*60*60; // 1 hour
$cookie_path = "/"; // All subfolders
$cookie_domain = "domain.com"; // All subdomains
setcookie($cookie_name, $cookie_data, $cookie_time, $cookie_path, $cookie_domain);
// When cookie creation unsuccessfull
if(!setcookie){
//Store login data in session
session_start();
$_SESSION['login_key'] = md5($email);
$_SESSION['auth'] = 'candidate';
$_SESSION['first_name'] = $getAccount3['first_name'];
}Code: Select all
list($loginkey,$author) = split("+|+",$cookie_data);Thank you,