Created
March 29, 2012 06:48
-
-
Save kankaungmalay/2234287 to your computer and use it in GitHub Desktop.
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 | |
if(isset($_POST['submit'])){ | |
// REST Server URL | |
$request_url = 'http://localhost/drupal710/webservice/user/login'; | |
// User data | |
$test = array( | |
'username' => $_POST['username'], | |
'password' => $_POST['password'], | |
); | |
$user_data = json_encode($test); | |
// 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); | |
}//endif | |
?> | |
<form action="" method="post"> | |
User Name:<input type="text" name="username" maxlength="12" size="12"/> <br/> | |
Password:<input type="password" name="password" maxlength="36" size="12"/> <br/> | |
<p><input type="submit" name="submit" /></p> | |
</form> |
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 | |
if(isset($_POST['submit'])){ | |
// REST Server URL | |
$request_url = 'http://localhost/drupal710/webservice/user/login'; | |
// User data | |
$user_data = array( | |
'username' => 'kankaung', | |
'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); | |
}//endif | |
?> | |
<form action="" method="post"> | |
User Name:<input type="text" name="username" maxlength="12" size="12"/> <br/> | |
Password:<input type="password" name="password" maxlength="36" size="12"/> <br/> | |
<p><input type="submit" name="submit" /></p> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment