[thelist] JS Cookie problem - more info!
Tom Dell'Aringa
pixelmech at yahoo.com
Fri Jan 10 13:50:07 CST 2003
Ok, figured something out! Again, what I am doing is looking for a
few cookies within my cookie string. These cookies start with "pid"
and have a number after them, like:
pid121=5
pid7=4
Because I don't know how many might be in a cookie, or what the
values are, I figured I would run through a loop to the highest
number pid could be, and check for each one.
So - my code to do that was this:
--------------------------------
pidMaxValue = 200;
for(x=1; x<=pidMaxValue; x++)
{
labelTest = "pid" + x;
thisCookie = getCookieData("pid" + x);
}
---------------------------------
So, I am testing every value up to 200, calling the function each
time like: getCookieData("pid1") through getCookieData("pid200").
Now - HERE is the problem: In my getCookieData() function, it
searches for the label name of the cookie based on LENGTH:
---------------------------------
function getCookieData(labelName)
{
var labelLen = labelName.length;
//actual test cookie data below
var cookieData = "mode=43%3Ahershelr; pid110=5; pid111=1;
Login=2fc109d9262cd534eea2311af95715b006; pid107=1";
var cLen = cookieData.length;
while(i < cLen)
{
var j = i + labelLen;
var searchString = cookieData.substring(i,j);
if(searchString == labelName)
{
//matched cookie, get cookie info stuff etc.
}
--------------------------------------------------
Running a test file I found the problem: When "pid111" is present,
and the function takes the parameter "pid1" we get a MATCH at
pid111..why? Because the cLen (length of the cookie) is only 4 not 6!
So when it comes across:
3Ahershelr; pid110=5; pid111
in the cookie string, it sees pid1 as part of pid110 (or 111) and
matches it! DOH. This means I will get various returned bad values,
and I won't really be able to tell them from the real ones.
I would make the cLen always 6, but it ISN'T always 6. Any ideas? Is
there maybe a way to bread out the string between pid and the = sign
instead? Runnin on empty ideas here!
Tom
=====
var me = tom.pixelmech.webDeveloper();
http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
More information about the thelist
mailing list