ユーザー名とパスワードのフィールドを持つサンプル アプリ (app1 など) があります。ユーザーが値を送信すると、別の Web サイト ログイン ページ (app2 など) で資格情報を確認する必要があります。app2 のログインが成功すると、ホームにリダイレクトされます。 app1 のページ...
PHP経由で可能ですか?
ユーザー名とパスワードのフィールドを持つサンプル アプリ (app1 など) があります。ユーザーが値を送信すると、別の Web サイト ログイン ページ (app2 など) で資格情報を確認する必要があります。app2 のログインが成功すると、ホームにリダイレクトされます。 app1 のページ...
PHP経由で可能ですか?
もちろん。データを含めて、site2 に対して curl リクエストを実行する必要があります。次に、結果を確認します。ログイン操作が成功すると、ユーザーをリダイレクトできます。
//You have recived username and password in post method, now it is time to log user in site2
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://example.com/login.php');
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'login='.$_POST['login'].'&password='.$_POST['password']);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, 'full path cookie.txt');
curl_setopt($c, CURLOPT_COOKIEJAR, 'full path cookie.txt');
$page = curl_exec($c);
curl_close($c);
//If he typed in wrong password, on site2 should be some error.
$error_text = 'Incorrect login or password'; //Text that will show on site after unsuccessful login attempt
//Check if is there any error on site2
if (strpos($page, $error_text) !== false) {
header('Location: http://www.example.com/'); //Everything seems to be ok, when do you want to redirect user?
} else {
echo 'You typed in incorrect username or password';
}