[英]Check whether user is logged in another domain
我正在網站上使用遠程登錄功能從我的網站登錄onapp服務器。這實際上將使用CURL獲取表單並使用用戶名和密碼提交。 一切正常。 現在,我的網站為單個用戶提供了不同的服務,因此onapp服務器中有多個帳戶。 因此,我需要一種方法來檢查onapp服務器中是否存在會話(如果用戶已經登錄)。如果用戶已經登錄onapp,將不允許再次登錄並顯示已經有一個用戶登錄。因此需要注銷用戶並使用新憑據登錄。 任何想法如何做到這一點。 ?
我認為這可以幫助您
// REST Server URL
$request_url = 'http://localhost:3000/rest_api/user/login';
// User data
$user_data = array('username' => 'jimthunderbird',
'password' => '123456', );
// cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $request_url);
curl_setopt($curl, CURLOPT_POST, 1);
// Do a regular HTTP POST
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($user_data)); // Set POST data
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl);
print $response;
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Check if login was successful
if ($http_code == 200) {
// Convert json response as array
$logged_user = json_decode($response);
} else {
// Get error msg
$http_message = curl_error($curl);
die($http_message);
}
print_r($logged_user);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.