Follow redirects


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function follow_redirects($url,$timeout=5)
  2. {
  3. $ch = curl_init($url);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6. curl_setopt($ch, CURLOPT_NOBODY, true);
  7. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  8. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  9. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061024 BonEcho/2.0");
  10.  
  11. $html = curl_exec($ch);
  12. $info = array();
  13. if(!curl_errno($ch))
  14. {
  15. $info = curl_getinfo($ch);
  16. return $info['url'];
  17. }
  18. return $url;
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.