February 19th, 2000, 01:03 AM
Hello. I am building a "custom links" feature on a web site. Currently, I am storing the url in a cookie and the name of the web site in another cookie. Having 10 custom links would mean 20 cookies. However, in the specifications of cookies (Netscape), there is a maximum limit of 20 on the number of cookies per domain. My question is: I know of a site at
which got around the problem by using a BIG cookie with all the information separated by a delimiter such as %. Would would be the code to parse this string in the cookie?
Suppose the contents of my cookie is:
CookieName = "URL1%site1.com%NAME1%site#1%URL2%site2.com%NAME2%site#2%URL3%site3.comNAME3%site#3..." How would I parse this string to get the following variables?
$URL1 = "site1.com"
$NAME1 = "site#1"... etc
Also, what would be a good delimiter to use? Is % very compatible?
Thank you for your help and I am very hungry for some more cookies
February 19th, 2000, 07:03 AM
Check out explode() and split() in the manual. As for a delimiter I wouldn't use % as that's used in url coding to delimit an encoded character. Pipe's (|) are good, usually.
However, you might want to use serialize()/unserialize() as an alternative. Store everything in a 2d array ($site[name], $site[url], etc) then $mycookie=serialize($site) and put $mycookie in the cookie. When you remove it just $site=unserialize($mycookie). Then you have no limits on cookies and only have to store one.
February 19th, 2000, 06:47 PM
Thanks for the answer. However, I am confused about 2D arrays after reading the PHp documentation. I tried site = $fav_name_1; but that did not work. So if I have the following variables stored already: $fav_path_1, $fav_name_1, $fav_path_2 and $fav_name_2, what would be the code to create a 2D array and to serialize/unserialize it? Should I worry about urlencoding the string? What about each() and list()? Should I care about them? Sorry about being such a newbie but any help would be greatly appreciated.
February 19th, 2000, 07:06 PM
You forgot the $ before site.
After you have your array set up you can do this:
Then you can setcookie with $data.
After you read the cookie do:
each and list can be used, if you want or you can just use the array. Up to you.
February 20th, 2000, 03:52 AM
February 23rd, 2000, 11:07 AM
If I needed to track that much information about a user I'd probably store the urls and such in a database. That way you need only to store one or two cookies such as a username and session id. Which would relate directly back to the information in the DB.
This would give you great flexibility and allow you to store as many links as the user wants.