Hello everyone. I'm having a problem with my cookie. What I'm trying to do is this:
When user logs in and checks the "remember me" checkpoint, i want to save his username to $_COOKIE['user']. [] For that I am checking whether the $rem variable is set. If this is not the case, the cookie will be deleted along with the username. Here are the pieces of code:

if (isset($_POST['remember']))
$rem = $_POST['remember'];
...
if (isset($rem))
{
    setcookie('user', $userName, time()+3600);
}
else
{
    setcookie('user', $userName, time()-3600); 
}

If the "remember me" box is not checked, cookie is "deleted". Next, in the next script, I am checking whether $_COOKIE['user'] [] is set.

if (isset($_COOKIE['user']));
{
    $smarty->assign("cookiedUser", $_COOKIE['user']);  -> this is where error occurs (with $_COOKIE).
}

And lastly, if there is username in cookie, it is written in .tpl file.
So, I am not really sure where does the "Undefined Index" error come from because i am checking with isset, so please help.
I will be glad to post some more code if needed. Thanks in advance. :)

I have to point out that everything works, only there is undefined error on top and it really bugs me. :)

If you are getting undefined index error, it means the $_COOKIE array does not contain the 'user' index, which in turn means that $_POST['remember'] is not set. Can you provide the html part of the code? Just want to check if you have used form method="post" or "get"...If it is "get", then change it to post.

<form id = 'log' name='logging' method='POST' action = 'login.php'>

                <input class= "form_checkbox" type = 'checkbox' name= 'remember' value = '1' /> Remember me <br/>                                                  

</form>

Here is the html part (it is actually .tpl file). Could you tell me maybe how to resolve this? And why does the error occur if I have placed the "if" statement before using the actual cookie?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.