4 $post_data = array( 'url' => 'http://planetozh.com/', 'keyword'=>'ozh', 'format'=>'json' );
\r
6 // Init the CURL session
\r
8 curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1/ozh.in/yourls-api.php"); // URL of the API file
\r
9 curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result
\r
10 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // AUTH with any (best) method available
\r
11 curl_setopt($ch, CURLOPT_USERPWD, 'ozh:richward'); // login/pwd as defined in config.php
\r
12 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
\r
13 curl_setopt($ch, CURLOPT_POST, 1); // This is a POST request
\r
14 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // Data to POST
\r
16 // Grab URL and return content
\r
17 $data = curl_exec($ch);
\r
20 // Echo result (either a new short URL, or an error message beginning with "Error")
\r
21 echo htmlentities($data);
\r