Forum Moderators: coopster

Message Too Old, No Replies

Losing Cookie Variables

... cookie exists but its empty

         

grahamberends

11:18 pm on Jan 26, 2006 (gmt 0)

10+ Year Member



Hi Everyone!

I'm losing variables from my cookie_string.

Puzzled! Can you please help?!

My test browser (Mozilla) is set to accept all cookies and ask. So the browser does receive the cookies. And, the expire is set to 30 minutes. Si it looks good - at least from the browser side!

Here is my cookie data, captured immediately after reading the returned cookie, printed at the bottom of my HTTP output:

cookie_parts:
my_access->login_reader_test:
[ graham ] => Graham_cookie_is_set
[ cookie_name ] => PHPSESSID
[ cookie_str_element_0 ] => 1a542f4bbc3508854c6cbbe4681a5352
[ user ] => 1a542f4bbc3508854c6cbbe4681a5352
[ language ] =>
[ location_focus ] =>
[ auth_iso ] =>
[ expire ] =>

As you can see there is no array data. The only array element is the first element of the cookie. All other variables are blank!

Here are extracts from my user_access_class.php


1)
/* At the start of user_access_class.php */
session_set_cookie_params(30 * 60, "/");
session_start();
//etc

2)
/* explode cookie */
function login_reader(){
if (isset($_COOKIE[$this->cookie_name])) {
$this->cookie_str = explode(chr(31), $_COOKIE[$this->cookie_name]);
$this->user = $this->cookie_str[0];
$this->user_pw = base64_decode($this->cookie_str[1]);
$this->language = $this->cookie_str[2];
$this->location_focus = $this->cookie_str[3];
$this->auth_iso = $this->cookie_str[4];
}
/* ... decide on access, etc */
}

3)
/* set cookie */
function generate_cookie() {
$expire = time()+2592000; //Note: this time+ is ignored!
$cookie_str = $this->user.chr(31);
$cookie_str .= base64_encode($this->user_pw).chr(31);
$cookie_str .= $this->language.chr(31);
$cookie_str .= $this->location_focus.chr(31);
$cookie_str .= $this->auth_iso;
setcookie($this->cookie_name, $cookie_str, $expire, $this->cookie_path,"www.".$this->host_name, 0);
}

4)
/* allow or deny access */
function access_authorisation() {
IF ( $this->access_authorised ) {
/* allow access, ie: let the requested page execute */
return;
} else {
/* deny access; close session and relocate to a login page */
session_write_close();
header("Location: ".$this->login_front_page);
exit();
}
}

Can you help explain why I get blanks in my cookie string?

Look forward to your replies
GrahamB

FalseDawn

2:25 am on Jan 27, 2006 (gmt 0)

10+ Year Member



if you are sure the cookie values are being set correctly (i.e. they aren't blank when they are set), then I'd try a different delimeter than chr(31) - a pipe maybe?