2016-04-07 11 views
0

私は2つのサーバー(つまり、異なるログインページを持つserver1とserver2)を持っています。2台の異なるサーバーの1回限りの認証方法は?

サーバー1
login_server1.php

<form method="post" action="$ACTION$"> 
    <input name="auth_user" type="email"> 
    <input name="auth_pass" type="password"> 
    <input name="redirurl" type="hidden" value="$REDIRURL$"> 
    <input name="accept" type="submit" value="Login"> 
</form> 

だから、ログインエラーで、サーバー1に戻り

login_server1_error.php

<form method="post" action="$ACTION$"> 
    <p class="login-error">$MESSAGE$</p> 
    <input name="auth_user" type="email"> 
    <input name="auth_pass" type="password"> 
    <input name="redirurl" type="hidden" value="$REDIRURL$"> 
    <input name="accept" type="submit" value="Login"> 
</form> 


サーバー2は、このサーバー上のURLにログインして、そのURLに移動するための自動認証を自動で行います。これはプロセスです

<?php 
/* 
AutoAuth Script 
*/ 

# Define Server2 URL & AutoAuth Key 
$server2url = "http://server2/dologin.php"; 
$autoauthkey = "abcXYZ123"; 

$timestamp = time(); # Get current timestamp 
$email = "[email protected]"; # Clients Email Address to Login 
$goto = "clientarea.php?action=products"; 

$hash = sha1($email.$timestamp.$autoauthkey); # Generate Hash 

# Generate AutoAuth URL & Redirect 
$url = $server2url."?email=$email&timestamp=$timestamp&hash=$hash&goto=".urlencode($goto); 
header("Location: $url"); 
exit; 

?> 

sever1フォームの送信アクションを実行すると、server2urlにアクセスする方法を教えてください。 のServer1最初のログインページで

答えて

0

私は$ _POSTに問題を解決してい...

は、私が書いてきた:

<form method="post" action="$ACTION$"> 
    <input name="auth_user" type="email"> 
    <input name="auth_pass" type="password"> 
    <input name="redirurl" type="hidden" value="$REDIRURL$"> 
    <input name="accept" type="submit" value="Login"> 
</form> 

そしてその二login_errorページでこの:

... 
</head> 
<?php 
    $user_email = $_POST['auth_user']; # For retrieve user email entered before this page 
    $user_pwd = $_POST['auth_pass']; # For retrieve user password entered before this page 
?> 
<script> 
    if $MESSAGE$=="Insufficient" { 

     <?php 
      /* 
      Auto Authentification code 
      */ 
      # Define URL & AutoAuth Key 
      $server2url = "http://server2/dologin.php"; 
      $autoauthkey = "abcXYZ123"; 

      $timestamp = time()-10; # Get current timestamp 
      $email = "$user_email"; # Clients Email Address to Login 
      $goto = "clientarea.php?action=products"; 

      $hash = sha1($email.$timestamp.$autoauthkey); # Generate Hash 

      # Generate AutoAuth URL & Redirect 
      $url = $server2url."?email=$email&timestamp=$timestamp&hash=$hash&goto=".urlencode($goto); 
      header("Location: $url"); 
      exit; 
     ?> 
    } 
</script> 

<body> 
<form method="post" action="$ACTION$"> 
    <p class="login-error">$MESSAGE$</p> 
    <input name="auth_user" type="email"> 
    <input name="auth_pass" type="password"> 
    <input name="redirurl" type="hidden" value="$REDIRURL$"> 
    <input name="accept" type="submit" value="Login"> 
</form> 
</body> 

ログイン情報が良好な最初のlogin.htmlページでユーザーが[送信]ボタンをクリックするとコードが正常に機能します(ただしクレジットは不十分です) SIにアクセスするために)、データはサーバ1に送信されます。クライアントクレジットはSIにアクセスするには「不十分」であることがわかります。したがって、(サーバ1)はlogin_error.htmlページで応答します。このスクリプトは最初に_POST [データ]情報を取得するスクリプトを実行し、次にユーザーの情報をServer2の自動ログインページにリダイレクトします。

難しいと思われるほど単純すぎるので、これは本当にかわいいです。

お楽しみください!

関連する問題