我做了一个简单的注册/登录脚本。它确实运行良好,但是现在,我无法显示HTML标签(锚标签)。在我实施删除Cookie之前,该方法已经奏效。这是我的导航代码:
<div class="nav-wrapper z-depth-1">
<a href="index.php" class="brand-logo center">Todo <i class="material-icons right">add_circle_outline</i></a>
<h6 id="loginName" class="valign-wrapper"><?php echo "Eingeloggt als: ". $_COOKIE['user']; ?></h6>
<?php
if(!isset($_COOKIE["user"])){
echo '<a href="register.php" class="right" id="register">Registrieren</a><a href="login.php" class="right" id="login">Einloggen</a>';
}else {
echo '<a href="logout.php" class="right" id="logout">Ausloggen</a>';
}
?>
</div>
成功登录后,我设置了cookie:
if (isset($_POST["username"]) && isset($_POST["password"]))
{
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT username FROM user WHERE username = :feldwert";
$kommando = $db->prepare($sql);
$wert = $username;
$kommando -> bindParam(':feldwert', $wert);
$kommando -> execute();
if($kommando->rowCount() > 0){
echo "Benutzer existiert!";
$sql = "SELECT username, password FROM user WHERE username ='".$username."';";
$erg = $db->query($sql);
foreach ($erg as $row){
$user = $row["username"];
$pass = $row["password"];
if(password_verify($password, $pass)){
setcookie("user", $user, time() + 60*60*12);
header("Location: index.php");
}else {
echo "Falschen Benutzernamen oder Passwort eingegeben!";
}
}
我的注销脚本如下:
<?php
setcookie("user","", 0);
header("Location: index.php");
?>
即使这不会删除cookie,我还是手动将其删除(或像使用firefox-addon一样),仍然没有定位标记。