Jump to content

Problem reading a cookie


BillyB

Recommended Posts

Hello all. Newbie here. I have a question regarding cookies.

 

I have set two cookies in script #1, namely EditingTraining and EditSPMarketing, but only seem to be able to read one of them in script #2.

 

Excerpts from the script are below. I'm hoping the problem has something to do with the way that I've coded the scripts, but am really quite perplexed as to why this isn't working.

 

 

Script #1

setcookie("EditTraining", $row['EditTraining'], time()+5184000, '/');

setcookie("EditSPMarketing", $row['EditSPMarketing'], time()+5184000, '/');

 

Script #2

$EditTraining = $_COOKIE['EditTraining'];

$EditSPMarketing         = $_COOKIE['EditSPMarketing'];

echo "EditSPMarketing: $EditSPMarketing<br>";

echo "EditTraining: $EditTraining<br>";

 

Output

EditSPMarketing:

EditTraining: 1

 

As you can see from the output, EditTraining displays '1' while EditSPMarketing seems to contain a null value. I have used echo to display the value of both columns before I set the cookie and EditSPMarketing definitely displays a value, but only one seems to get written to a cookie.

 

What am I doing wrong here?

 

Thank you,

 

BillyB

 

Link to comment
Share on other sites

I've finally found the answer. There is a LIMIT to the number of cookies that PHP can handle. That limit is 20! By using Garethp's print_r($_COOKIE); command I had, indeed, exceeded the Cookie Threshold. I did a bit more searching on the Interweb and came across this possible solution, which I will be trying out tomorrow.

 

PHP Cookie limit

Wondering why some cookies are not set? The maximum number is 20. The maximum total size only 2 KB. They are set in the reverse direction of the script. And they must be accessed by the same directory in which they have been set. If you use 'include' the original script will determine the active directory, not the included one.

You can exceed the number of 20 by putting the values into one string seperating with a character of you choice:

$all="$a;$b;$c;$d";

setcookie('all',$all,time()+10000);

 

 

and unpack it with explode:

$x=$_COOKIE['all'];

$y=explode(';',$x);  // ';' is the seperator

$a=$y[0];$b=$y[1]; and so on.....

 

Thank you for your help.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.