Guest User

Untitled

a guest
Oct 4th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. array(2) { ["errorDetailCode"]=> int(-44) ["errorDetailMessage"]=> string(37) "username or password not found" }
  2.  
  3. array(2) { ["errorDetailCode"]=> int(-2) ["errorDetailMessage"]=> string(23) "username not found" }
  4.  
  5. array(2) { ["errorDetailCode"]=> int(-1) ["errorDetailMessage"]=> string(19) "password not found" }
  6.  
  7. $km_username = filter_var($_POST['userName'], FILTER_SANITIZE_STRING);
  8. $km_user_password = $_POST['userPassword'];
  9.  
  10. // Validate form fields if they are empty
  11. if(empty($km_username) && empty($km_user_password)) {
  12.  
  13. // Error message if email and password fields are empty
  14. $_SESSION['km_error_message'] = 'Insert username and password!';
  15. header('Location: '.KM_BASE_URL.'/login.php');
  16. exit();
  17.  
  18. }else if(empty($km_username)) {
  19.  
  20. // Error message if username field is empty
  21. $_SESSION['km_error_message'] = 'Insert username!';
  22. header('Location: '.KM_BASE_URL.'/login.php');
  23. exit();
  24.  
  25. }else if(empty($km_user_password)) {
  26.  
  27. // Error message if password field is empty
  28. $_SESSION['km_error_message'] = 'Insert password!';
  29. header('Location: '.KM_BASE_URL.'/login.php');
  30. exit();
  31.  
  32. }
  33.  
  34. // Store form fields into an array
  35. $fields = array(
  36. 'userid' => $km_username,
  37. 'password' => $km_user_password
  38. );
  39.  
  40. // cURL request to API
  41. $cURL = curl_init();
  42. curl_setopt($cURL, CURLOPT_URL, URL_LOGIN_API);
  43. curl_setopt($cURL, CURLOPT_POST, 1);
  44. curl_setopt($cURL, CURLOPT_POSTFIELDS, http_build_query($fields));
  45. curl_setopt($cURL, CURLOPT_HEADER, 0);
  46. curl_setopt($cURL, CURLOPT_RETURNTRANSFER, TRUE);
  47.  
  48. $cURL_response = curl_exec($cURL); // execute the curl command
  49.  
  50. if (curl_error($cURL)) {
  51. echo curl_error($cURL);
  52. }
  53.  
  54. curl_close ($cURL);
  55.  
  56. $json_response = json_decode($cURL_response, true);
  57.  
  58.  
  59. // Form validation after cURL request
  60.  
  61. if(isset($json_response['errorDetailCode'])){
  62.  
  63. // Error message if cURL request error
  64. $_SESSION['km_error_message'] = $json_response['errorDetailMessage'];
  65. header('Location: '.KM_BASE_URL.'/login.php');
  66. exit();
  67.  
  68. }else{
  69.  
  70. // Store the cookie file name into the session
  71. if (!isset($_SESSION['cookiefile'])) {
  72. $cookiefile = tempnam(".", "cookie");
  73. $_SESSION['cookiefile'] = basename($cookiefile);
  74. file_put_contents($cookiefile, "");
  75. }
  76.  
  77. // cURL request to API
  78. $ch = curl_init();
  79. curl_setopt($ch, CURLOPT_URL, URL_LOGIN_API);
  80. curl_setopt($ch, CURLOPT_POST, 1);
  81. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
  82. curl_setopt($ch, CURLOPT_HEADER, 0);
  83. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  84. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); // Cookie aware
  85. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); // Cookie aware
  86. $content = curl_exec($ch);
  87. curl_close($ch);
  88.  
  89. // Redirerct user to dashboard
  90. header('Location: '.KM_BASE_URL.'/client-dashboard.php');
  91. exit();
  92.  
  93. }
Add Comment
Please, Sign In to add comment