Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement