站点 1 具有 php 功能,站点 2 具有表单,两个站点位于不同的服务器上。完成此任务的最简洁方法是什么?
站点 2 上的表单是一个非常简单的登录,带有“电子邮件”和“密码”。
站点 1 上的 php 类称为 Shopper,如果站点 2 上的表单上的凭据正确,我需要在 Shopper 类中运行登录方法。
我觉得我的元素在这里..这样的事情会起作用吗?如果是这样,我将如何实例化 Shopper 类并运行登录功能?我需要使用 SOAP 协议吗?
任何和所有的帮助将不胜感激。谢谢你。
public function login($password) {
global $db;
if (!$this->get_email()) {
return false;
}
// Log them in now that we know who they are.
$vars = array();
$vars[] = array(':i_email_id', $this->get_email());
$vars[] = array(':i_password', $password);
// This also exists, but is not yet in use:
// $token = $db->get_function_as_proc('custom.japi_shopper_identity.login_by_username(:i_username, :i_password)', $vars);
$token = $db->get_function_as_proc('custom.japi_shopper_identity.Login_by_Email(:i_email_id, :i_password)', $vars);
// todo: what if it's bad credentials?
if ($token == null) {
return false;
} else {
$this->set_sign_in_token($token);
return $this->get_sign_in_token();
}
}
只是为了澄清:
登录页面(站点B):
<form id='register' action='http://siteA/test/profile' onsubmit="return validateForm()" method='post' accept-charset='UTF-8'>
<fieldset>
<legend>Log In</legend><br/>
<label for='email' >Email Address*:</label>
<input type='text' name='email' id='email' maxlength="50" /><br/><br/>
<label for="password">Password*:</label>
<input type="password" name="password" placeholder="password" required><br/><br/>
<input type='submit' name='Submit' value='Submit' />
</fieldset>
</form>
<?php
$username = $_POST['email'];
$password = $_POST['password'];
$shopper = new Shopper($username);
$token = $shopper->login($username, $password);
echo json_encode(array("token" => $token));
print_r ($_POST);
?>
操作页面(站点A):
$shopper = new Shopper($email);
$shopper->login($password);
$cInit = curl_init("http://siteB/test/login");
curl_setopt_array($cInit, array(
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>urlencode(implode("&", array("email" => $email, "password" => $password)))
));
$content = curl_exec($cInit);
$err = curl_errno($cInit);
$errmsg = curl_error($cInit);
$results = json_decode($content);
//$results = array("token" => "pleasework" );
这看起来对吗?