我有兩個域中的兩個文件登錄與PHP另一個域捲曲
http://example1.com/remote_login.php
和
http://example2.com/login.php
當用戶訪問http://example1.com/remote_login.php
我想要做一些remote_login.php驗證,那我以後想要發佈username
和password
到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";
}
你試過了什麼? – 2012-08-10 03:53:41
見編輯:....) – 2012-08-10 03:57:14
我高解決方案,但其長途徑。 – 2012-08-10 04:36:39