こんな簡単な方法で良いのだろうか?セキュリティ的に危ないのかな?
<?php
include("logincheck.php");
include('config.php');
session_start();
//ここに会員ページコンテンツを書く
?>
<?php
$auth_id ="ログインID";
$auth_pass ="ログインパスワード";
function h($str){
if(is_array($str)){
return array_map("h",$str);
}else{
return htmlspecialchars(stripslashes($str),ENT_QUOTES,"UTF-8");
}
}
function getSha1Password($s) {
return (sha1("3k1L7Alyb".$s));
}
<?php
session_start();
if(empty($_SESSION["login_name"])){
header("Location:login_auth.php");
exit;
}
<?php
include("config.php");
include("functions.php");
session_start();
$error_message=<<<eof
IDとパスワードを入力してログインしてください
eof;
if($_SERVER["REQUEST_METHOD"] == "POST"){
if($_POST["auth_id"] == $auth_id and $_POST["auth_pass"] == $auth_pass){
session_regenerate_id(true);
$random_id = mt_rand(0, 10);
$_SESSION["login_name"] = getSha1Password($random_id);
header("Location:index.php");
exit;
}else{
$error_message = "IDもしくはパスワードが間違っています。";
}
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>ログインページ</title>
</head>
<?php echo $error_message; ?>
<form action="" method="post">
ID:<input type="text" name="auth_id" />
パスワード:<input type="text" name="auth_pass" />
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>
コメント