charanv Posted December 3, 2009 Share Posted December 3, 2009 Hi All I would like to design a page which takes the url as input and outputs the final url. It should follow any redirects. Any idea on how to get this done. Thank you Charan Link to comment https://forums.phpfreaks.com/topic/183865-php-link-checker/ Share on other sites More sharing options...
premiso Posted December 3, 2009 Share Posted December 3, 2009 Look into curl as I believe it can follow redirects. Link to comment https://forums.phpfreaks.com/topic/183865-php-link-checker/#findComment-970607 Share on other sites More sharing options...
mattal999 Posted December 3, 2009 Share Posted December 3, 2009 This works for me (PHP5): <?php function getHeadersCurl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 15); $r = curl_exec($ch); $r = split("\n", $r); return $r; } function getNextLocation($headers) { $array = $headers; $count = count($array); for($i=0; $i < $count; $i++) { if(strpos($array[$i], "ocation:")) { $url = substr($array[$i], 10); } } if($url) { return $url; } else { return 0; } } function getFinalPage($url) { $go = 1; $i = 1; while($go && $i < 6) { $headers = getHeadersCurl($url); $go = getNextLocation($headers); if($go) { $url = $go; } $i++; } return $url; } echo getFinalPage("http://wave.google.com/"); ?> Link to comment https://forums.phpfreaks.com/topic/183865-php-link-checker/#findComment-970623 Share on other sites More sharing options...
charanv Posted December 8, 2009 Author Share Posted December 8, 2009 Thank You all especially "mattal999" for your help I appreaciate the time and effor you guys have put in.. I will test the code tonight,.. Link to comment https://forums.phpfreaks.com/topic/183865-php-link-checker/#findComment-973776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.