Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1.  
  2. /*
  3. * YOURLS : sample file showing how to use the API
  4. * This shows how to tap into your YOURLS install API from *ANOTHER* server
  5. * not from a file hosted on the same server. It's just a bit dumb to make a
  6. * remote HTTP request to the server the request originates from.
  7. *
  8. * Rename to .php
  9. *
  10. */
  11.  
  12. // EDIT THIS: your auth parameters
  13. $username = 'joe';
  14. $password = '123456';
  15.  
  16. // EDIT THIS: the query parameters
  17. $url = 'http://planetozh.com/blog/'; // URL to shrink
  18. $keyword = 'ozh'; // optional keyword
  19. $title = 'Super blog!'; // optional, if omitted YOURLS will lookup title with an HTTP request
  20. $format = 'json'; // output format: 'json', 'xml' or 'simple'
  21.  
  22. // EDIT THIS: the URL of the API file
  23. $api_url = 'http://your-own-domain-here.com/yourls-api.php';
  24.  
  25. // Init the CURL session
  26. $ch = curl_init();
  27. curl_setopt( $ch, CURLOPT_URL, $api_url );
  28. curl_setopt( $ch, CURLOPT_HEADER, 0 ); // No header in the result
  29. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // Return, do not echo result
  30. curl_setopt( $ch, CURLOPT_POST, 1 ); // This is a POST request
  31. curl_setopt( $ch, CURLOPT_POSTFIELDS, array( // Data to POST
  32. 'url' => $url,
  33. 'keyword' => $keyword,
  34. 'title' => $title,
  35. 'format' => $format,
  36. 'action' => 'shorturl',
  37. 'username' => $username,
  38. 'password' => $password
  39. ) );
  40.  
  41. // Fetch and return content
  42. $data = curl_exec($ch);
  43. curl_close($ch);
  44.  
  45. // Do something with the result. Here, we just echo it.
  46. echo $data;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement