api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client_auth.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require "../lib/php_crud_api_transform.php";
  3. $cookiejar = tempnam(sys_get_temp_dir(), 'cookiejar-');
  4. function call($method, $url, $csrf = false, $data = false) {
  5. global $cookiejar;
  6. $ch = curl_init();
  7. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  8. curl_setopt($ch, CURLOPT_URL, $url);
  9. $headers = array();
  10. if ($data) {
  11. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  12. $headers[] = 'Content-Type: application/json';
  13. $headers[] = 'Content-Length: ' . strlen($data);
  14. }
  15. if ($csrf) {
  16. $headers[] = 'X-XSRF-TOKEN: ' . $csrf;
  17. }
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  20. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
  21. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
  22. return curl_exec($ch);
  23. }
  24. // in case you are using php-api-auth:
  25. $csrf = json_decode(call('POST','http://localhost/api.php/', false, 'username=admin&password=admin'));
  26. $response = call('GET','http://localhost/api.php/posts?include=categories,tags,comments&filter=id,eq,1', $csrf);
  27. unlink($cookiejar);
  28. $jsonObject = json_decode($response,true);
  29. $jsonObject = php_crud_api_transform($jsonObject);
  30. $output = json_encode($jsonObject,JSON_PRETTY_PRINT);
  31. ?>
  32. <html>
  33. <head>
  34. </head>
  35. <body>
  36. <pre><?php echo $output ?></pre>
  37. </body>
  38. </html>