#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Cleveland
    Posts
    16
    Rep Power
    0
    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
    http://www.hammervald.se/search-this/

    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
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    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[0][name], $site[0][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.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Cleveland
    Posts
    16
    Rep Power
    0
    Thanks for the answer. However, I am confused about 2D arrays after reading the PHp documentation. I tried site[0][1] = $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.
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    You forgot the $ before site[0][1].

    After you have your array set up you can do this:

    $data=serialize($site);
    Then you can setcookie with $data.

    After you read the cookie do:
    $site=unserialize($data);

    I don't use cookies much, but I don't think you need to urlencode them. Try it and find out.

    each and list can be used, if you want or you can just use the array. Up to you.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Cleveland
    Posts
    16
    Rep Power
    0
    Thank you!
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    2
    Rep Power
    0
    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.

Similar Threads

  1. include external page that uses cookies
    By micahbdavis in forum PHP Development
    Replies: 1
    Last Post: February 9th, 2004, 04:03 PM
  2. netscape problem with cookies in php ?
    By fordfasterr in forum PHP Development
    Replies: 0
    Last Post: November 29th, 2003, 08:19 AM
  3. cant delete cookies random errors
    By toxical in forum PHP Development
    Replies: 2
    Last Post: November 26th, 2003, 05:16 AM
  4. Sessions and cookies problem
    By nathanks in forum PHP Development
    Replies: 3
    Last Post: November 11th, 2003, 10:40 AM
  5. Skins using cookies.
    By coolkhan in forum HTML Programming
    Replies: 14
    Last Post: November 5th, 2003, 08:50 PM

IMN logo majestic logo threadwatch logo seochat tools logo