I am using a remote login feature in my website for logging into an onapp server from my site.. This will actually fetch the form using CURL and submitting it with user name and password. It is working fine. Now my site has got different services for a single user and so there is multiple accounts in the onapp server. So I need a method to check if there is a session is existing in the onapp server(if a user is already logged in).If a user is already logged in onapp, will not allow another login and will show there is a user already logged in. So it is needed to logout the user and login using the new credentials. Any idea how this can be done. ?
Asked
Active
Viewed 1,107 times
1 Answers
0
This one I think it could help you
// 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);

MvG
- 57,380
- 22
- 148
- 276

Muhammad Asif Mahmood
- 1,650
- 1
- 9
- 10
-
Actually what I need is not to check whether a user is logged in after executing the login function. What I need is to check whether a user session exist from the same browser. That is users can log into the onapp interface directly also. So if a user is already logged in from the same browser, it will not allow another user login. Also multiple user logins can occur as I am creating specific accounts for each of the service the the user will order from my site. – Happy Coder Nov 16 '12 at 08:25
-
Do you have access to the OnApp Control Panel server? The access logs to the UI are in there. You could then check if the same IP is accessing different user IDs. – arikin Feb 10 '14 at 02:13