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

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