Skip to content

Instantly share code, notes, and snippets.

@meancode
Created August 30, 2010 04:56
Show Gist options
  • Save meancode/557026 to your computer and use it in GitHub Desktop.
Save meancode/557026 to your computer and use it in GitHub Desktop.
<?php
$username = 'namehere';
$password = 'passhere';
$url = '<$mt:EntryPermalink$>'; // This would be for Movable Type
$format = 'simple';
$api_url = 'http://domain.com/yourls-api.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
curl_setopt($ch, CURLOPT_POST, 1); // This is a POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, array( // Data to POST
'url' => $url,
'format' => $format,
'action' => 'shorturl',
'username' => $username,
'password' => $password
));
$data = curl_exec($ch);
curl_close($ch);
echo $data;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment