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
\r
6 * not from a file hosted on the same server. It's just a bit dumb to make a
\r
7 * remote HTTP request to the server the request originates from.
\r
10 // EDIT THIS: your auth parameters
\r
12 $password = '123456';
\r
14 // EDIT THIS: the query parameters
\r
15 $url = 'http://planetozh.com/blog/'; // URL to shrink
\r
16 $keyword = 'ozh'; // optional keyword
\r
17 $format = 'json'; // output format: 'json', 'xml' or 'simple'
\r
19 // EDIT THIS: the URL of the API file
\r
20 $api_url = 'http://yoursite/yourls-api.php';
\r
22 // Init the CURL session
\r
24 curl_setopt($ch, CURLOPT_URL, $api_url);
\r
25 curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result
\r
26 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
\r
27 curl_setopt($ch, CURLOPT_POST, 1); // This is a POST request
\r
28 curl_setopt($ch, CURLOPT_POSTFIELDS, array( // Data to POST
\r
30 'keyword' => $keyword,
\r
31 'format' => $format,
\r
32 'action' => 'shorturl',
\r
33 'username' => $username,
\r
34 'password' => $password
\r
37 // Fetch and return content
\r
38 $data = curl_exec($ch);
\r
41 // Do something with the result. Here, we just echo it.
\r