Skip to content

Commit 54f4acb

Browse files
committed
Made this clearer, see #175
1 parent 27984be commit 54f4acb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/client_auth.php

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

0 commit comments

Comments
 (0)