see fooobar.com/questions/1308508 / ...
I implemented to get each line of a text file with one shortened URL per line corresponding to a redirect URL:
<?php // input: textfile with one bitly shortened url per line $plain_urls = file_get_contents('in.txt'); $bitly_urls = explode("\r\n", $plain_urls); // output: where should we write $w_out = fopen("out.csv", "a+") or die("Unable to open file!"); foreach($bitly_urls as $bitly_url) { $c = curl_init($bitly_url); curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'); curl_setopt($c, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($c, CURLOPT_HEADER, 1); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 20); // curl_setopt($c, CURLOPT_PROXY, 'localhost:9150'); // curl_setopt($c, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); $r = curl_exec($c); // get the redirect url: $redirect_url = curl_getinfo($c)['redirect_url']; // write output as csv $out = '"'.$bitly_url.'";"'.$redirect_url.'"'."\n"; fwrite($w_out, $out); } fclose($w_out);
Have fun and enjoy! Pw
source share