IsraelTorres

revshorturl.php

Jun 7th, 2011
282
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. ?>
RAW Paste Data