Last active
April 2, 2018 23:07
-
-
Save noriyukitakei/14f70f52066de4faf4601f696f3ecc3d 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 | |
// データベースの接続情報などを定義している共通処理をrequireします。 | |
require_once __DIR__.'/server.php'; | |
// セッションを開始します。 | |
session_start(); | |
// ユーザー名とパスワードが入力されていたら、ログイン処理を開始します。 | |
if (!empty($_POST["username"]) && !empty($_POST["password"])) { | |
// データベースの接続に必要なPDOインスタンスを作成します。 | |
$pdo = new PDO($dsn, $username, $password); | |
// 入力したユーザー名と一致するパスワードをデータベースから取得します。 | |
$stmt = $pdo->prepare('SELECT * FROM oauth_users WHERE username = ?'); | |
$stmt->execute(array($_POST["username"])); | |
$result = $stmt->fetch(PDO::FETCH_ASSOC); | |
// 入力したパスワードと、データベースのパスワードが一致しているか | |
// どうかを確認します。 | |
if ($_POST["password"] == $result["password"]) { | |
// ユーザー名をセッションに格納します。 | |
$_SESSION['username'] = $_POST["username"]; | |
// ログイン画面に来る前の画面に戻ります。 | |
// ログイン画面にリダイレクトされる際に、セッション変数backに戻り先の | |
// URLを格納しておくことが必須です。 | |
header("Location: ".$_SESSION['back']); | |
exit; | |
} | |
} | |
?> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Facebookログイン</title> | |
</head> | |
<body> | |
<h2>Facebookログイン画面</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