I make popup box to show user about my website information by using jquery ui. Now, I want to show this popup box to every user that are registered or not when they open my website.
so, I create two php script file like static.php
and dynamic.php
to show popup box to user. dynamic.php
for the registered user and static.php
for non register user.
I have no problem in dynamic.php
. For static.php, I create cookie to check if the user is already answer or not. But its not working. Here is my code.
$cookie = "";
$rnd_cookie="";
if(isset($_COOKIE['user_id']) && $_COOKIE['user_id']==$cookie) {
echo "this static user already answer<br/>";
echo "cookie ".$_COOKIE['user_id']."<br/>";
echo "check_cookie ".$cookie."<br/>";
} else {
$rnd_cookie = rand()*1000;
setcookie("user_id",$rnd_cookie,time()+28800);//expire time 8 hrs
echo "create cookie value: $rnd_cookie<br/>";
echo "cookie: ".$_COOKIE['user_id']."<br/>";
$cookie = $_COOKIE['user_id'];
check();
}
After searching about my problem, I know the problem that is I can't get cookie value immediately after setting cookie like this,
setcookie("user_id",$rnd_cookie,time()+28800);//expire time 8 hrs
$cookie = $_COOKIE['user_id'];
I have no idea how to check user can see popup or not with cookie. I very appreciate for any suggestion.