I have been using Matt Liebson's cookie.lib for all my (limited) cookie work. It has been working fine, but for one application, I need to know whether the cookie was accepted before I go on. My algorithm looks like this:
if(cookie already exists)
do stuff
else #set a cookie
If the client's browser is set to reject cookies, there is no error message, and the script goes merrily along, except that any variables that depended on the cookie's contents end up with null values.
I tried extending the algorithm to test for the cookie's existence immediately after setting it, figuring this would let me know whether it was successfully set. i.e.
if(cookie already exists)
do stuff
else #set a cookie
get the cookie
if(successfully got the cookie)
everything is fine
else
print an error message about need to have cookies enabled
this all works fine if the cookie already exists. However, whether or not cookies are enabled, it always goes to the error message the first time, even though the cookie ends up getting set just fine. (Subsequent calls to the script find the cookie ok). I think what is happening is that the call to get the cookie (to check for its existence) is coming too quickly after setting it.
Is there a better way to check to see if the cookie was accepted before progressing? Do I just need some changes to this algorithm? Any solution must take care of the situation where a user has set his browser to warn of cookies and accepting them individually.
This script must run on a number of different servers, so I do not want to rely on having a specific module available - I'd rather use a library.
I look forward to any advice.
Roy
if(cookie already exists)
do stuff
else #set a cookie
If the client's browser is set to reject cookies, there is no error message, and the script goes merrily along, except that any variables that depended on the cookie's contents end up with null values.
I tried extending the algorithm to test for the cookie's existence immediately after setting it, figuring this would let me know whether it was successfully set. i.e.
if(cookie already exists)
do stuff
else #set a cookie
get the cookie
if(successfully got the cookie)
everything is fine
else
print an error message about need to have cookies enabled
this all works fine if the cookie already exists. However, whether or not cookies are enabled, it always goes to the error message the first time, even though the cookie ends up getting set just fine. (Subsequent calls to the script find the cookie ok). I think what is happening is that the call to get the cookie (to check for its existence) is coming too quickly after setting it.
Is there a better way to check to see if the cookie was accepted before progressing? Do I just need some changes to this algorithm? Any solution must take care of the situation where a user has set his browser to warn of cookies and accepting them individually.
This script must run on a number of different servers, so I do not want to rely on having a specific module available - I'd rather use a library.
I look forward to any advice.
Roy