如何对两个不同的服务器进行一次性身份验证?

时间:2016-04-07 12:25:31

标签: php html submit

我有两台服务器(即)server1和server2,它们具有不同的登录页面。

server1的
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>

因此,在登录错误时,server1返回

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>


Server2 提供自动验证功能,可以登录并转到此服务器上的网址。这是过程

<?php
/*
AutoAuth Script
*/

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

$timestamp = time(); # Get current timestamp
$email = "user@mail.com"; # 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?

1 个答案:

答案 0 :(得分:0)

我用$ _POST ...

解决了这个问题

Server1 首次登录页面中,我写道:

<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)时,代码现在正常(ei),数据被发送到 Server1 。它看到客户信用“不足以”访问SI。因此,它( Server1 )使用login_error.html页面进行响应,该页面首先执行脚本以检索_POST [data]信息,然后将用户的信息重定向到 Server2 的自动登录页。

这听起来很漂亮,因为它太简单了,难以理解。

享受!