I made it so that users could check ‘remember me’ on a login form and it would set cookies. Now if they logout it directs them to logout.php and the cookies should be deleted. It all works except i get these error messages.
Notice: Undefined index: username in C:\xammp\htdocs\mine\logout.php on line 6
Notice: Undefined index: password in C:\xammp\htdocs\mine\logout.php on line 7
My code for logout.php is
<?php
session_start();
if (isset($_SESSION['username'])) {
setcookie('username', $_POST['username'], false, '/');
setcookie('password', $_POST['password'], false, '/');
session_destroy();
echo "You've benn logged out. <a href='index.php'>Click here</a> to return.";
} else {
die ('You are not logged in!');
}
Just use
isset($_POST['username'])?$_POST['username']:''instead of$_POST['username']And
isset($_POST['password'])?$_POST['password']:''instead of$_POST['password']See: Ternary Operator