]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - test-api.php
No cookie storing when called by API
[Github/YOURLS.git] / test-api.php
1 <?php\r
2 \r
3 /*\r
4  * YOURLS : sample file showing how to use the API\r
5  */\r
6 \r
7 // EDIT THIS: your auth parameters\r
8 $username = 'joe';\r
9 $password = '123456';\r
10 \r
11 // EDIT THIS: the query parameters\r
12 $url = 'http://planetozh.com/caca'; // URL to shrink\r
13 $keyword = 'caca';                              // optional keyword\r
14 $format = 'json';                               // output format: 'json', 'xml' or 'simple'\r
15 \r
16 // EDIT THIS: the URL of the API file\r
17 $api_url = 'http://127.0.0.1/ozh.in/yourls-api.php';\r
18 \r
19 // Init the CURL session\r
20 $ch = curl_init();\r
21 curl_setopt($ch, CURLOPT_URL, $api_url);\r
22 curl_setopt($ch, CURLOPT_HEADER, 0);            // No header in the result\r
23 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result\r
24 curl_setopt($ch, CURLOPT_POST, 1);              // This is a POST request\r
25 curl_setopt($ch, CURLOPT_POSTFIELDS, array(     // Data to POST\r
26                 'url'      => $url,\r
27                 'keyword'  => $keyword,\r
28                 'format'   => $format,\r
29                 'username' => $username,\r
30                 'password' => $password\r
31         ));\r
32 \r
33 // Fetch and return content\r
34 $data = curl_exec($ch);\r
35 curl_close($ch);\r
36 \r
37 // Do something with the result. Here, we just echo it.\r
38 echo $data;\r
39 \r
40 ?>