Advertisement
IsraelTorres

revshorturl.php

Jun 7th, 2011
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?php
  2. // found on http://bigtrapeze.com/?p=82
  3. // added cli handling for using in termial
  4. if ($argc == 2){
  5. $ch = curl_init();
  6. $myurl=$argv[1];
  7. echo "$myurl\n";
  8. curl_setopt($ch, CURLOPT_URL, $myurl);
  9. curl_setopt($ch, CURLOPT_HEADER, 1);
  10. curl_setopt($ch, CURLOPT_NOBODY, 1);
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  13.  
  14. $result = curl_exec($ch);
  15.  
  16. if (preg_match("/Location\:/","$result")) {
  17.     $url = explode("Location: ",$result);
  18.     $reversed_url = explode("\r",$url[1]);
  19.     echo $reversed_url[0];
  20. } else {
  21.     print_r($result);
  22. }
  23. echo "\n";
  24. }
  25. else{
  26.     echo "usage: $argv[0] 'short url'\n";
  27. }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement