• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cookie question?

#1
[eluser]R_Nelson[/eluser]
I'm creating a user Cookie that looks like this :
Code:
$cookie = array(
                    'name'   => 'user',
                    'value'  => $id,
                    'expire' => '2400000'
                );

My question is will it work if i add an array in where $id is?

the array would be something like
Code:
$user = array (
                    'id' => $id,
                    'username' => $username,
                    'password' => $password
                );
or do i need to create 1 cookie for each pram?

Im getting error
Quote:A PHP Error was encountered

Severity: Warning

Message: setcookie() expects parameter 2 to be string, array given

Filename: core/Input.php

Line Number: 254

#2
[eluser]InsiteFX[/eluser]
Code:
$user = array (
    'id' => $id,
    'username' => $username,
    'password' => $password
);

$cookie_data = $this->user;

Now set your cookie using $cookie_data for your value.

You may want to serialize and unserialize your $cookie_data
You view the session.php class to see how it is done!

InsiteFX

#3
[eluser]R_Nelson[/eluser]
Quote:You may want to serialize and unserialize your $cookie_data
You view the session.php class to see how it is done!

that's so it encodes it right?

#4
[eluser]R_Nelson[/eluser]
if i create the cookie using $cookie_data wouldn't i be missing the name and expire?

#5
[eluser]InsiteFX[/eluser]
1) Yes thats to encode it.

2) No, the only thing you put in $cookie_data is the values you want to store.
Code:
$cookie = array(
     'name'   => 'The Cookie Name',
     'value'  => $cookie_data,   // will hold your array values but in a string.
     'expire' => '86500',
     'domain' => '.some-domain.com',
     'path'   => '/',
     'prefix' => 'myprefix_',
     'secure' => TRUE
);

setcookie($cookie);

InsiteFX

#6
[eluser]R_Nelson[/eluser]
thats how i got the error in the first place!

#7
[eluser]InsiteFX[/eluser]
Did try to serialize it first?

InsiteFX

#8
[eluser]R_Nelson[/eluser]
no i did not. would that make a difference?

#9
[eluser]InsiteFX[/eluser]
My fault, sorry

The input class is using codeigniters set_cookie but the one in the session library is using php's setcookie

So this line should be:
Code:
setcookie($cookie); // not set_cookie
set_cookie will not accept an array.
I edited the above code.

I would encode and encrypt the cookie, you can see how they do it in the system/libraries/session.php file _set_cookie

InsiteFX

#10
[eluser]R_Nelson[/eluser]
the encrypt thing works just fine for session cookies but it dose not encrypt the normal user cookies for login i supouse i could 5d5 them or sha1 them then compare them to the database one md5 or sha1


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.