I have my login page and I want to set the cookie when the user has successfully logged in, my issue is the cookies are not working
here is my code what I doing wrong ?
thanks in advance
I have my login form validation on header.php (where I have my database connect and all my configs)
this is my form on index.php:
<form id="form-entrada" action="<?=$base_url?>/login" method="POST">
<div id="login-inner">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Username</th>
<td><input type="text" name="username" class="login-inp" /></td>
</tr>
<tr>
<th>Password</th>
<td><input type="password" name="password" class="login-inp" /></td>
</tr>
<tr>
<th></th>
<td valign="top"><input type="checkbox" name="remember" class="checkbox-size" id="login-check" /><label for="login-check">Remember password</label></td>
</tr>
<tr>
<th></th>
<td><input type="submit" name="submit" class="submit-login" value="true" /></td>
<input type="hidden" name="subFormLogin" value="true">
</tr>
</table>
</div>
</form>
This is my php login :
if(isset($GET["logout"]) && ($GET["logout"] == true)) {
session_destroy();
session_start();
header ("Location: $base_url");
}
if($_POST["subFormLogin"] == true) {
$username = $_POST["username"];
$password = md5($salt.$_POST["password"]);
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
if (!$result = mysqli_query($connect,$sql)) {
$loginError = true;
header ("Location: $base_url/login/erro");
} elseif (mysqli_num_rows($result) != 1) {
$loginError = true;
header ("Location: $base_url/login/erro");
} else {
$registo = mysqli_fetch_assoc($result);
$_SESSION["autenticado"] = true;
$_SESSION["username"] = $username;
$_SESSION["name"] = $registo["name"];
$_SESSION["iduser"] = $registo["iduser"];
$_SESSION["active"] = $registo["active"];
header ("Location: $base_url");
}
if (isset($_POST['remember'])){
setcookie("myusername", $_SESSION['username'], time()+92000, "/");
setcookie("mypassword", $_SESSION['password'], time()+92000, "/");
if (isset($_COOKIE['username']) && isset($_COOKIE['password'])){
$_SESSION['username'] = $_COOKIE['myusername'];
$_SESSION['password'] = $_COOKIE['mypassword'];
}
}
}
Is not showing any error.