よし、ここまでだ。必要に応じて、別のものを用意Virtual Host
してauthproject.net
ください。そして、認証情報をそこのフォームに投稿します。セッションで設定します。
ここで、資格情報をauthproject.net
ドメインに提供し、認証後にどこに移動するかを指定すると、認証データがそれぞれの宛先に送信されます。
のソースtestproject1.net/index.php
:
<?php
if (isset($_SESSION["user"]))
die($_SESSION["user"]["name"] . " is logged in!");
else
die('<a href="auth.php">Login</a>');
?>
のソースtestproject1.net/auth.php
:
<?php
if (isset($_SESSION["user"]) && !count($_POST))
{
header("Location: index.php");
die();
}
elseif (count($_POST))
if ($_POST["username"] == "admin" && $_POST["password"] == "letmein")
$_SESSION["user"]["title"] = "Administrator"; # The session is set
else
showForm(); # Invalid Password
else
showForm(); # Log In Screen
?>
<?php
session_start();
if (isset($_SESSION["user"]) && !count($_POST))
{
header("Location: index.php");
die();
}
elseif (count($_POST))
if ($_POST["username"] == "admin" && $_POST["password"] == "letmein")
{
$_SESSION["user"]["title"] = "Administrator"; # The session is set
if (isset($_GET["redirect"]))
{
# Start crappy implementation :P
echo '<form method="post" action="', $_GET["redirect"], '/auth.php" id="authfrm"><input type="hidden" name="username" value="', $username, '"><input type="hidden" name="password" value="', $password, '"></form><script type="text/javascript">document.getElementById("authfrm").submit();</script>';
}
else
header("Location: index.php");
}
else
showForm(); # Invalid Password
else
showForm(); # Log In Screen
?>
すべてのサイトで同じことが行われます。あなたがそれを得る願っています。