Created
April 3, 2018 01:10
-
-
Save noriyukitakei/f2a3bbd6fae45c773b7cde277922aa35 to your computer and use it in GitHub Desktop.
OAuthコンシューマー側のログイン画面
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// セッションを開始します。 | |
session_start(); | |
// ユーザー名とパスワードが入力されていたら、ログイン処理を開始します。 | |
if (!empty($_POST["username"]) && !empty($_POST["password"])) { | |
$username = $_POST["username"]; | |
$userpassword = $_POST["password"]; | |
// データベースの接続に必要なPDOインスタンスを作成します。 | |
$pdo = new PDO('mysql:dbname=consumer;host=localhost', 'root', 'password'); | |
// 入力したユーザー名と一致するパスワードをデータベースから取得します。 | |
$stmt = $pdo->prepare('SELECT * FROM consumer_users WHERE username = ?'); | |
$stmt->execute(array($username)); | |
$result = $stmt->fetch(PDO::FETCH_ASSOC); | |
// 入力したパスワードと、データベースのパスワードが一致しているか | |
// どうかを確認します。 | |
if ($_POST["password"] == $result["password"]) { | |
// ユーザー名をセッションに格納します。 | |
$_SESSION['username'] = $username; | |
// ログイン画面に来る前の画面に戻ります。 | |
// ログイン画面にリダイレクトされる際に、セッション変数backに戻り先の | |
// URLを格納しておくことが必須です。 | |
header("Location: ".$_SESSION['back']); | |
exit; | |
} | |
} | |
?> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Twitterログイン</title> | |
</head> | |
<body> | |
<h2>Twitterログイン画面</h2> | |
<form action="/login.php" method="POST"> | |
ID:<input type="text" name="username" value=""> | |
<br> | |
Password:<input type="password" name="password" value=""> | |
<br> | |
<input type="submit" name="login" value="ログイン"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment