Advertisement
Guest User

requestlogin

a guest
Feb 9th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. $apiURL = "https://portalqa.kyrioscloud.com/users/sign_in?format=json";
  2. $apiusername = filter_var($_SESSION['username']);
  3. $apipassword = filter_var($_SESSION['password']);
  4.  
  5. $jsoncredentials = "{\"user\":" . "{\"email\":\"" . $apiusername . "\",\"password\":\"" . $apipassword . "\"}}";
  6. $obj = (object) [
  7. 'user' => ['email' => $apiusername, 'password' => $apipassword]
  8. ];
  9.  
  10. $options = array(
  11. 'http' => array(
  12. 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
  13. 'method' => 'POST',
  14. 'content' => http_build_query($obj)
  15. )
  16. );
  17. $context = stream_context_create($options);
  18. $result = get_headers($apiURL, false, $context);
  19. if (strpos(json_encode($result), 'HTTP/1.1 401 Unauthorized') !== false) { /* Handle error */
  20. session_destroy();
  21. header('Location: ../../public_html/login.php');
  22. } else {
  23. $temp = explode(" ", $result[10]);
  24. $temp = explode("=", $temp[1]);
  25. $token = explode(";", $temp[1]);
  26.  
  27. $temp = explode(" ", $result[11]);
  28. $temp = explode("=", $temp[1]);
  29. $sessionID = explode(";", $temp[1]);
  30.  
  31. $_SESSION["XSRF-TOKEN"] = $token[0];
  32. $_SESSION["_session_id"] = $sessionID[0];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement