Jump to content

Problem with Cookie detection


Recommended Posts

I am using PHP to set a cookie and have a problem with detecting the cookie afterwards.In the script I check if cookie exsits with if(isset($_COOKIE["abc"]))if it does then I make a change to the expiry dateif it doesnt then I create a cookie with setcookie....I then check again to see if the cookie now exists and at this point the check says it doesnt exists and therefore displays my "please enable cookies message".I know that the setcookie works because if I reload the page the script detects the cookie correctly and no longer displays the message.Is this something to do with server side and client side and when the cookie is actually created or is it something else

Link to post
Share on other sites

I don't know if this is your situation, butremember that the $_COOKIE array is populated when your script begins to run. It is not dynamic. Updates to cookie data do not show in the $_COOKIE array until the next time the script runs. The solution is simply to build in another test condition for the situations where you are setting the cookie.

Link to post
Share on other sites
I am using PHP to set a cookie and have a problem with detecting the cookie afterwards.In the script I check if cookie exsits with if(isset($_COOKIE["abc"]))if it does then I make a change to the expiry dateif it doesnt then I create a cookie with setcookie....I then check again to see if the cookie now exists and at this point the check says it doesnt exists and therefore displays my "please enable cookies message".I know that the setcookie works because if I reload the page the script detects the cookie correctly and no longer displays the message.Is this something to do with server side and client side and when the cookie is actually created or is it something else
Cookies always give a problem when it is call after <!DOCTYPE Always Call Cookie & Header before <!DOCTYPE called because COOKIE Will set before HTML Request to the browser Edited by samgenius
Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...