| | |
Multiple values in one cookie
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 9
Reputation:
Solved Threads: 0
Hi All
I am a bit of a begginer in PHP.
How do I store multiple vales in a cookie?
I am going along the lines of:
then something like (not sure about the sytax here)::
Basically how do I get the information into and out of the cookie.
Thanks in advance for any help.
I am a bit of a begginer in PHP.
How do I store multiple vales in a cookie?
I am going along the lines of:
php Syntax (Toggle Plain Text)
$data = array('apple'=>'green', 'orange'=>'orange', 'banana'=>'yellow');
then something like (not sure about the sytax here)::
php Syntax (Toggle Plain Text)
$var=implode($data); setcookie('data', $var, time() +3600);
Basically how do I get the information into and out of the cookie.
Thanks in advance for any help.
Last edited by peter_budo; Apr 16th, 2009 at 8:03 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Hi,
Why don't you concatenate values in a string like
Why don't you concatenate values in a string like
PHP Syntax (Toggle Plain Text)
apple,orange,mango and then store it in cookie.
Vivek Rawat
Keep solving complexities.
Keep solving complexities.
Well if you want to implode the values and store it in the cookie then you'd explode it to retrieve it as an array.
php Syntax (Toggle Plain Text)
$array = array('orange', 'green', 'blue'); $string = implode(',', $array); // 'orange,green,blue' $second_array = explode(',', $string); // array('orange', 'green', 'blue');
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Well you did it in your example. All I did was explain the correct syntax for implode/explode. Also, see www.php.net/cookies
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Apr 2009
Posts: 9
Reputation:
Solved Threads: 0
Hi
Thanks again for all the help, my head is going round and round as I have been at thsi for so long now. i right in saying to set the cookie I :
and that has set the cookie?
I know how to set and then get everything out of a normal cookie
I alsoknw how to use the array but put them both together and I have a total block. I just cannot get my head round getting the data from within the array that is stored in the cookie. I have read your link but it is not helping me as I think my brain is fried.
Any help very very gratefully accepted.
Thanks again for all the help, my head is going round and round as I have been at thsi for so long now. i right in saying to set the cookie I :
php Syntax (Toggle Plain Text)
$data = array('apple'=>'green', 'orange'=>'orange', 'banana'=>'yellow'); $var=implode( ',', $data); setcookie('data', $var, time() +3600);
I know how to set and then get everything out of a normal cookie
I alsoknw how to use the array but put them both together and I have a total block. I just cannot get my head round getting the data from within the array that is stored in the cookie. I have read your link but it is not helping me as I think my brain is fried.
Any help very very gratefully accepted.
Last edited by peter_budo; Apr 16th, 2009 at 8:03 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
If you know how to set and get data from the cookie I just gave you how to use implode/explode, just put them together. You already did the first part in your original post.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
![]() |
Similar Threads
- Session share across multiple domains same IP (PHP)
- sleep function (PHP)
- retreving value from database and displaying them in tree menu. (PHP)
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- impose a limitation on form of time duration (PHP)
- HELP- My computer keeps freezing after fedora core 5 installation (*nix Software)
- Php With Sessions Aah (PHP)
Other Threads in the PHP Forum
- Previous Thread: Parsing error on non existant line
- Next Thread: Parse error: syntax error, unexpected $end
Views: 1459 | Replies: 16
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date datepart directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql oop parse password paypal pdf php problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web webdesign xml youtube






