Subcookies, the PHP version

Posted on 29 May 2007 (01:54 PM)

As a follow-up to my last article, Take your cookies to the next level with Subcookies, I wrote a PHP equivalent.

You can download the PHP file here as a Zip archive. The file contains two classes: CookieJar and SubCookieJar. Both work in the same way as their Javascript counterparts from the previous article. There are a few things to notice though:

Also, note this little oddity:

  1. if (CookieJar::fetch('admin'))
  2. CookieJar::crumble('admin');
  3.  
  4. SubCookieJar::bake('admin',array('name'=>'Harmen','age'=>22,'homepage'=>'whatstyle.net'),2);
  5. $a = SubCookieJar::fetch('admin','name');
  6. $b = SubCookieJar::fetch('admin','homepage');
  7. $c = SubCookieJar::fetch('admin','age').'';
  8.  
  9. SubCookieJar::crumble('admin','age',2);
  10. $d = CookieJar::fetch('admin');
  11.  
  12. print $a;
  13. print '<br>';
  14. print $b;
  15. print '<br>';
  16. print $c;
  17. print '<br>';
  18. print $d;
  19. Download this code: /code/subcookies_php3.txt

The variable $c will not contain a value! I'm not sure why, 'cause I fetched the value before crumbling the subcookie, but it's not there. If anyone knows why this happens, please let me know.

For more information about the principles of subcookies, read my last article.

Back to top

Filed under PHP

Comments:

No comments have been added yet, you could be the first!

Sorry, due to spam, comments are temporarily out of order.

Back to top

Preferences

These settings will be saved for your convenience.