Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie not working - maximum length hit?

Status
Not open for further replies.

MarlaJ

Programmer
Jul 21, 2003
20
US
I'm having a problem with my cookies. It was working perfectly and then my boss asked me to add a few things so I added them to the cookie. Once I added the 11 new 1/0 (tinyint datatype) items my cookie started dropping the items it stored in the cookie first. I tried changing the cookie name for just the 11 items so it would be in a different cookie but it does the same thing. Here's my code, everything after testcookie[admin] was one of the 11 added.
Code:
		setcookie("testcookie[userid]","$userid",time()+315360000);
									setcookie("testcookie[fname]","$fname",time()+315360000);
									setcookie("testcookie[lname]","$lname",time()+315360000);
									setcookie("testcookie[email]","$email",time()+315360000);
									setcookie("testcookie[tt]","$tt",time()+315360000);
									setcookie("testcookie[news]","$news",time()+315360000);
									setcookie("testcookie[dm]","$dm",time()+315360000);
									setcookie("testcookie[calendar]","$calendar",time()+315360000);
									setcookie("testcookie[whitepapers]","$whitepapers",time()+315360000);
									setcookie("testcookie[subscriptions]","$subscriptions",time()+315360000);
									setcookie("testcookie[phone]","$phone",time()+315360000);
									setcookie("testcookie[mac]","$mac",time()+315360000);
									setcookie("testcookie[dept]","$dept",time()+315360000);
									setcookie("testcookie[yearsexp]","$yearsexp",time()+315360000);
									setcookie("testcookie[levelexp]","$levelexp",time()+315360000);
									setcookie("testcookie[crm]","$crm",time()+315360000);
									setcookie("testcookie[login]","yes",time()+315360000);									
									setcookie("testcookie[admin]","$admin",time()+315360000);
									setcookie("testcookie2[base_sas]","$base_sas",time()+315360000);
									setcookie("testcookie2[sas_stat]","$sas_stat",time()+315360000);
									setcookie("testcookie2[sas_eg]","$sas_eg",time()+315360000);
									setcookie("testcookie2[sas_eis]","$sas_eis",time()+315360000);
									setcookie("testcookie2[sas_af]","$sas_af",time()+315360000);
									setcookie("testcookie2[sas_intrnet]","$sas_intrnet",time()+315360000);
									setcookie("testcookie2[sas_mddb]","$sas_mddb",time()+315360000);
									setcookie("testcookie2[sas_eminer]","$sas_eminer",time()+315360000);
									setcookie("testcookie2[sas_ets]","$sas_ets",time()+315360000);
									setcookie("testcookie2[sas_graph]","$sas_graph",time()+315360000);
									setcookie("testcookie2[sas_connect]","$sas_connect",time()+315360000);

The cookie file is only 2kb and I'm using IE 5.5. It's under the 4kb max size but I don't know if there's a maximum character limit on a cookie or if there's something else going on. I don't know if I have a php issue, browser issue or it's the cookie. Any suggestions?
 
I suggest that you migrate to using sessions.
Since the session data is kept server side there is no limit on how much data you keep. The session cookie would just contain the PHPSessID and you will not have to take browser limits etc. into consideration.
It will either work on not.
 
There is also a limit to the number of total cookies a site can set. Most browsers follow the Netscape whitepaper that introduced cookies ( and that document says that a browser should be prepared to accept 20 cookies from a site.

From the looks of your cookie names, I strongly recommend you look into session variables. One cookie is set to store all of that, and session variables can be singleton variables, arrays, or even objects.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Interesting - I had read that you could only use 4 cookies per site, not 20.

I am using session variables for login as well but it depends on if a person logs in and wants the site to remember the person next time he/she visits.

I have been thinking of changing the cookies to hold less, but I was just looking for the quick fix my boss wanted.
 
The failure of your code seems to happen around the 20th cookie you're trying to set. There may be some other cookies' being set that you aren't aware of (like when sessions are automatically on).

Frankly, you're very much overusing cookies. I don't know the nature of the data involved, but is it possible to set the identifying cookie (if the user wants the site to remember him) and then fetch all the rest of your data from that single cookie?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top