How to Cakephp 2x User Login thorught curl outside form cakephp.
After successfully Login i want to get login user details or login not success get message "login failed"
this is my cakephp directory
cakephp->app
cakephp->demo
Below my code:
Demo/index.php
$urltopost = "http://localhost/eventapp/users/androide_login";
$fields = array(
'User'=>array(
'username' => 'demo',
'password' => '123456789'
)
);
$fields_string = http_build_query($fields);
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, false);
$returndata = curl_exec ($ch);
curl_close ($ch);
print_r($returndata); //display the reuslt*/
This is my UsersController/login action
public function androide_login() {
if ($this->request->is('post')) {
if ($this->Auth->login($this->data)) {
$user = $_SESSION['Auth']['User'];
pr($this->Session->read('Auth.User'));
die;
}
else {
$this->Session->setFlash('Your username or password was incorrect.');
}
}
}
About the code not working properly.