私はログイン文を使ってユーザエントリを作成するためのログインページを修正しました。次のページのログアウトボタンはユーザを削除しますが、またログインページphpのリダイレクトとクッキーの削除
<head>
<?php
if(isset($_POST["Logout"])){
$saveuser = $_COOKIE["user"];
$savepass = $_COOKIE["password"];
$hostname='localhost';
$username='root';
$password='';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=cs266db_db1",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql3 = "DELETE FROM userid
WHERE user='".$saveuser."' AND password='".$savepass."'";
if ($dbh->query($sql3)) {
echo "<script type= 'text/javascript'>alert('Logged out');</script>";
}
else{
echo "<script type= 'text/javascript'>alert('Data not successfull.');</script>";
}
$dbh = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
unset($_COOKIE["user"]);
unset($_COOKIE["password"]);
}
?>
<?php
if(isset($_POST["submit"])){
$cookie_user = $_POST["user"];
$cookie_pass = $_POST["password"];
setcookie("user", $cookie_user, time() + (86400), "/");
setcookie("password", $cookie_pass, time() + (86400), "/");
$hostname='localhost';
$username='root';
$password='';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=cs266db_db1",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql2 = "INSERT INTO userid
VALUES ('".$cookie_user."','".$cookie_pass."')";
if ($dbh->query($sql2)) {
echo "<script type= 'text/javascript'>alert('Register Complete');</script>";
}
else{
echo "<script type= 'text/javascript'>alert('Data not successfull.'); </script>";
}
$dbh = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
}
?>
<?php
if(!isset($_COOKIE["user"])) {
echo"<form action="."''"."method="."post".">";
echo"<input type='"."text'"." name='"."user'"." placeholder='"."Enter Username'"." required/><br><br>";
echo"<input type='"."password'"." name='"."password'"." placeholder='"."Enter Password'"." required/><br><br>";
echo"<input type='"."submit'"." name='"."submit'"." value='"." Register'"."/>";
echo"</form>";
}
else {
header("Location: index_1.php"); /* Redirect browser */
exit();
}
?>
</head>
:ユーザーが登録となりますが、私のページは、私がログインしてユーザーが見られているので、それは次のページにつながる、ページを更新する必要があり、自動的に次のページにリダイレクトされません。これは私のコードです私がログアウトすると、ユーザーは正しく削除されますが、netbeansからページをロードすると、クッキーが削除されていないと思われるので、index_1
になりますか?どんな助けも素晴らしいだろう!もう一度私の質問はindex_1
に正しくリダイレクトする方法と、ログアウト時にCookieを正しく削除する方法です。
クッキーの使用を削除する場合は、「setcookie」http://php.net/manual/en/function.setcookie.php、 '$ _COOKIES'の割り当てと設定が無効になります –
** setcookie **ログアウトボタンは動作しません –
なぜパスワードをクッキーに保存していますか?それはセキュリティの観点からは良い考えではありません。特に暗号化されていなければログイン後はいつでもパスワードは必要ありません。 – Rasclatt