ProblemHelpPlease Posted August 1, 2011 Share Posted August 1, 2011 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 comment Share on other sites More sharing options...
jeffman Posted August 1, 2011 Share Posted August 1, 2011 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 comment Share on other sites More sharing options...
ProblemHelpPlease Posted August 1, 2011 Author Share Posted August 1, 2011 I realise the mistake I have made, should have read the manual in more depth.What is the best method to detect if a user has been to the website previously without using cookies or sessions. Link to comment Share on other sites More sharing options...
Ingolme Posted August 1, 2011 Share Posted August 1, 2011 There's no failproof way.Store their IP address, but that can change too. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted August 1, 2011 Author Share Posted August 1, 2011 Ah... think I have a solution for the cookie issue that should cover this anyway so will try that first. Link to comment Share on other sites More sharing options...
samgenius Posted August 2, 2011 Share Posted August 2, 2011 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 elseCookies 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.