PHP+Cookies: Show message once only -


i'm having problem short piece of code cannot work.

basically, want display 2 different messages, depending on whether user new or returning.

<?php  if(isset($_cookie['visit']) && ($_cookie['visit'] == "true"))  {    echo 'cookie set, welcome back'; }else{    echo 'cookie not set, welcome new user'; }  setcookie("visit", "true", time()+60*60*24*600);  ?> 

the problem cookie not being set. don't know wrong, can me?

you need move setcookie condition:

<?php  if(isset($_cookie['visit']) && $_cookie['visit'] == "true"){     echo 'cookie set, welcome back'; }else{     echo 'cookie not set, welcome new user';     setcookie("visit", "true", time()+60*60*24*600); } ?> 

if not working should check cookie being sent script. eg browser or browser addon interfering.

be aware there new law if server based in eu, requires obtain informed consent visitors before can store or retrieve any information on there computer. http://www.cookielaw.org/


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -