我在两个域中有两个文件
http://example1.com/remote_login.php
和
http://example2.com/login.php
当用户访问http://example1.com/remote_login.php
时,我想在 remote_login.php 中进行一些验证,之后我想发布username
andpassword
到 http://example2.com/login.php
如果结果成功,用户应该被重定向到http://example2.com/index.php
(我也在检查会话http://example2.com/index.php
)
任何的想法
Sorry for my bad english
我已经尝试使用它curl
,但它不起作用它会登录,但不会设置会话。所以用户无法重定向到index.php
$cookie="cookie.txt";
$data = array();
$data['global_id'] = "raj";
$data['global_password'] = "raj";
foreach ($data as $key => $value){
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
$curl_connection = curl_init('http://example2.com/login.php');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_connection, CURLOPT_FAILONERROR, TRUE);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_REFERER, 'http://example2.com/login.php');
curl_setopt($curl_connection, CURLOPT_POST, true);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl_connection, CURLOPT_HEADER, FALSE);
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($curl_connection, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($curl_connection, CURLOPT_SSLVERSION, 3); // OpenSSL issue
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, 0); // Wildcard certificate
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($curl_connection);
if($result){
header("Location: http://example2.com/index.php");
}
else{
echo "Login failed";
}