Trevors Posted August 5, 2006 Share Posted August 5, 2006 Hi all,Im curious if CURL can follow a link like this "http://www.blogcatalog.com/out/slike-iz-zivota-jednog-idiota.html" then when it redirects it pulls the real url and saves it.I was gonna crawl whole http://www.blogcatalog.com/ but they got redirect urls which i dont want.Would really appreciate abit of helpBest RegardsTrevor Quote Link to comment Share on other sites More sharing options...
shoz Posted August 6, 2006 Share Posted August 6, 2006 http://www.phpfreaks.com/forums/index.php/topic,96689.msg387319.html#msg387319 Quote Link to comment Share on other sites More sharing options...
Trevors Posted August 6, 2006 Author Share Posted August 6, 2006 Thanks mate :D really appreciate it Quote Link to comment Share on other sites More sharing options...
shoz Posted August 6, 2006 Share Posted August 6, 2006 I think I slightly misinterpreted your post even though the code snippet I linked you to does also have the answer. I thought you just wanted to get the address of the final url, but I realize now that you want the content (I think).You may have figured it out but know that the only curl option you need to set is CURLOPT_FOLLOWLOCATION for curl to follow the redirects.[code]curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);[/code][code]<?php$ch = curl_init();$url = 'http://example.com/website/hello/329472';curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$r = curl_exec($ch);$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);curl_close($ch)//$r has the content//$url has the address[/code]Note the removal of the NOBODY option. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.