0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

webarenaでubuntu その24

0
Last updated at Posted at 2019-08-22

概要

webarenaでubuntu18.04やってみた。
php7.2やってみた。
session認証やってみた。

login.php

<?php
	session_start();
	header ('Content-Type: text/html; charset=Shift_JIS');
?>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>
<body>
<form action="index.php" method="POST">
	ログインID:<input type="text" size="15" name="fLoginID"><br>
	パスワード:<input type="password" size="8" name="fPassword"><br>
	<input type="submit" value="ログイン">
</form>
</body>
</html>

index.php

<?php
	session_start();
	if ($_SERVER['REQUEST_METHOD'] === 'POST')
	{
		$fLoginID = $_POST['fLoginID'];
		$fPassword = $_POST['fPassword'];
		$db = new PDO("mysql:host=localhost;dbname=mydb;", 'arena', 'pass');
		$sql = "SELECT pass FROM test where flag='1' AND ID='$fLoginID'";
		$res = $db->query($sql);
		if ($res->rowCount() != 1)
		{
			header ('Content-Type: text/html; charset=Shift_JIS');
			print "アカウントが違う、もしくはユーザ登録されていません。";
			print '<a href="../">こちらから登録してください。</a>';
			session_destroy();
			exit;
		}
		$user = $res->fetch();
		if ($user["pass"] != $fPassword)
		{
			header ('Content-Type: text/html; charset=Shift_JIS');
			print "パスワードが違います。";
			session_destroy();
			exit;
		}
		$_SESSION['sLogin'] = "ok";
		$_SESSION['sId'] = $fLoginID;
		header("Location: contents.php");
	}
	else if ($_SESSION['sLogin'] <> "ok")
	{
		header("Location: login.php");
	}
	else
	{
		header("Location: contents.php");
	}
?>

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?