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