Created
April 13, 2012 21:51
-
-
Save cotto/2380383 to your computer and use it in GitHub Desktop.
services login example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Login | |
$login_data = array( | |
'username' => 'USER', | |
'password' => 'PASSWORD', | |
); | |
$base_url = "http://your-awesome-site.com/api"; | |
$req = new HttpRequest("$base_url/user/login.json", HttpRequest::METH_POST); | |
$req->setRawPostData(json_encode($login_data)); | |
$req->setContentType('application/json'); | |
$req->send(); | |
if ($req->getResponseCode() != 200) { | |
print_r($req); | |
echo "login failed\n"; | |
exit; | |
} | |
$response = $req->getResponseBody(); | |
$response = json_decode($response); | |
$session_cookie = array($response->session_name => $response->sessid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment