IsraelTorres icon

revshorturl.php

IsraelTorres | PRO | 06/07/11 09:15:55 PM UTC | 0 ⭐ | 546 👁️ | Never ⏰ | []
PHP |

640 B

|

None

|

0 👍

/

0 👎

<?php
// found on http://bigtrapeze.com/?p=82
// added cli handling for using in termial
if ($argc == 2){
$ch = curl_init();
$myurl=$argv[1];
echo "$myurl\n";
curl_setopt($ch, CURLOPT_URL, $myurl);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
 
$result = curl_exec($ch); 
 
if (preg_match("/Location\:/","$result")) {
    $url = explode("Location: ",$result);
    $reversed_url = explode("\r",$url[1]);
    echo $reversed_url[0];
} else {
    print_r($result);
}
echo "\n";
}
else{
    echo "usage: $argv[0] 'short url'\n";
}
?>

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎