<?php require_once './config.php'; if($_SESSION["login"] == 1){ header("Location: ./admin.php"); exit; } else{ header("Cache-Control: no-cache, must-revalidate"); header("content-type:text/html;charset=utf-8"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="ja"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>ログインフォーム</title> </head> <body> <form method="POST" action="./admin.php"> <table> <tr> <td> ユーザ名 </td> <td> <input name="user" type="text" value="<?=$_COOKIE["login_user"]?$_COOKIE["login_user"]:""?>" /> </td> </tr> <tr> <td> パスワード </td> <td> <input name="pass" type="password" /> </td> </tr> <tr> <td> ユーザ名を保存<input name="check" type="checkbox" value="1"<?=$_COOKIE["login_check"]==1?" checked":""?> /> </td> <td align="right"> <input type="submit" value="ログイン" /> </td> </tr> <?php if($_GET["error"] == "1"){ echo <<< HTML <tr> <td colspan="2"> ログインに失敗しました </td> </tr> HTML; } ?> </table> </form> </body> </html>
<?php header("content-type:text/html;charset=utf-8"); require_once './config.php'; if($_POST["user"] == USER && $_POST["pass"] == PASS || $_SESSION["login"] == 1){ if($_POST["check"] == 1){ #1か月保存 setcookie("login_check", $_POST["check"], time() + 60 * 60 * 24 * 30); setcookie("login_user", $_POST["user"], time() + 60 * 60 * 24 * 30); } else{ setcookie("login_check", $_POST["check"], time() -1); setcookie("login_user", $_POST["user"], time() -1); } $msg = "ログイン成功"; $_SESSION["login"] = 1; } else{ header("Location: index.php?error=1"); exit; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="ja"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>ログインフォーム</title> </head> <body> <?=$msg?> <br /><br /> <input type="button" value="ログアウト" onclick="window.location.href='./logout.php';" /> </body> </html>
<?php require_once './config.php'; unset($_SESSION["login"]); header("Location: ./index.php"); exit; ?>
<?php #ガーベジコレクションのルーチンを起動 ini_set('session.gc_probability', 1); #データがゴミとみなされる秒数 ini_set('session.gc_maxlifetime', 60*60); #ガーベジコレクションの働く確率 ini_set('session.gc_divisor', 100); #セッションキャッシュの保存パス session_save_path("./sess_cache/"); #セッションスタート session_start(); #アイパス define("USER", "nakano"); define("PASS", "nakano"); ?>