Skip to content

Instantly share code, notes, and snippets.

@cotto
Created April 13, 2012 21:51
Show Gist options
  • Save cotto/2380383 to your computer and use it in GitHub Desktop.
Save cotto/2380383 to your computer and use it in GitHub Desktop.
services login example
<?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