|
|
Subject:
Array cookie in PHP
Category: Computers > Programming Asked by: shantanuo-ga List Price: $2.00 |
Posted:
21 Jul 2003 23:48 PDT
Expires: 20 Aug 2003 23:48 PDT Question ID: 233626 |
Hi, I have written a feed reader for my personal use. The php code given below does work. But it works only with a single feed. How can I save multiple cookies (array?) and display a few more RSS feeds. The example page can be found at... http://shantanuoak.com/test1.php <?php if ($delete==yes) { setcookie ("FeedCookie5", $formfeedurl1,time()-3600); } if (isset($_COOKIE['FeedCookie5'])) { ?> <script language="javascript" src="http://forever.p3k.org/rss/rss-box.r?url=<?php echo "$FeedCookie5"; ?>&align=left&width=300&frameColor=black&titleBarColor=%23add8e6&titleBarTextColor= black&boxFillColor=white&textColor=black&fontFace=&maxItems=7&compact=&xmlButton=&j avascript=true"></script> <form action="test1.php"> <input type="text" name="formfeedurl1" size="26"> <input type="submit" name="Add" value="Add Feed"> </form> <a href="test1.php?delete=yes">Delete Cookie</a><br>Please referesh the page <?php exit; } { setcookie ("FeedCookie5", $formfeedurl1,time()+3600); } ?> <form action="test1.php"> <input type="text" name="formfeedurl1" size="26"> <input type="submit" name="Add" value="Add Feed"> </form> <a href="test1.php?delete=yes">Delete Cookie</a><br>Please refresh the page Thanks Shantanu Oak |
|
Subject:
Re: Array cookie in PHP
Answered By: sycophant-ga on 22 Jul 2003 12:34 PDT Rated: |
Hi shantanuo-ga , There are two ways to do what you want. The first is to store an array in the cookie, this can be done easily with serialize(). However I would steer away from storing potentially large volumes of data in a single cookie. The second and possibly better option is to store a number of cookies, and reconstitute them into an array within your software. You can see this file in action at http://dylan.wibble.net/programming/ga-test/233626/test.php The source is at: http://dylan.wibble.net/programming/ga-test/233626/test.txt My code is a bit verbose, and could be done better, but it demonstrates the principle well. By having predictable cookie names, it is easy to handle them. I hope that answers your question. Let me know if any of my code is unclear to you. Regards, Sycophant-ga | |
| |
|
shantanuo-ga
rated this answer:
Your marvellous code is worth a million dollars! Is it possible to rate 6 stars or 8 stars instead of just 5? |
|
Subject:
Re: Array cookie in PHP
From: sycophant-ga on 22 Jul 2003 02:44 PDT |
I have an answer for this, but for some reason I have been unable to post this through my ISP's proxy server. I am still trying. |
Subject:
Re: Array cookie in PHP
From: knowledge_seeker-ga on 22 Jul 2003 06:11 PDT |
Sycophant is experiencing technical difficulties and is unable to post an answer or further comments at this time. Rather than keep you waiting, he has asked that I post his answer for him. -K~ ==================================== Hi shantanuo-ga , There are two ways to do what you want. The first is to store an array in the cookie, this can be done easily with serialize(). However I would steer away from storing potentially large volumes of data in a single cookie. The second and possibly better option is to store a number of cookies, and reconstitute them into an array within your software. You can see this file in action at http://dylan.wibble.net/programming/ga-test/233626/test.php The source is at: http://dylan.wibble.net/programming/ga-test/233626/test.txt My code is a bit verbose, and could be done better, but it demonstrates the principle well. By having predictable cookie names, it is easy to handle them. I hope that answers your question. Let me know if any of my code is unclear to you. Regards, Sycophant-ga |
Subject:
Re: Array cookie in PHP
From: sycophant-ga on 22 Jul 2003 12:35 PDT |
Thank you knowledge-seeker, I have posted my answer above. Hopefully this way if shantanuo-ga has any problems I can be notified through the normal channels of any clarification requests. Regards, Sycophant-ga |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |