I am trying to set cookies to remember the users login details if they tick the 'remember me' box in the login form. I have managed to do this, however when I destroy the cookies by unticking the box, the login fields will both have undefined index errors in them the next time they try and login. How do I get rid of these errors when the cookie has been destroyed? here is the code for the cookies from my login.php:
if(isset($_POST['keep'])){
setcookie("blarg",$_POST["email"],time()+3600);
setcookie("bloof",$_POST["password"],time()+3600);
}else{
setcookie("blarg","",time()-3600);
setcookie("bloof","",time()-3600);
}
and here is the code to display the cookie data in my login form on my index page:
<input type="text" name="email" id="email" required="required" value="<?php echo $_COOKIE["blarg"] ?>"/>
<br />
<label>Password</label>
<input type="password" name="password" id="password" required="required" value="<?php echo $_COOKIE["bloof"] ?>"/>
<br />
Also this is just for a uni project, so it doesn't matter that the password is stored in a cookie, because I know that would be insecure in the real world.
Check if it exists first:
<input type="text"
name="email"
id="email"
required="required"
value="<?php if(isset($_COOKIE["blarg"])) { echo $_COOKIE["blarg"]; } ?>"
/>
Then do same for password field.