Jump to content

Archived

This topic is now archived and is closed to further replies.

Trevors

CURL question follow url and pull next url from url bar

Recommended Posts

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 help

Best Regards
Trevor

Share this post


Link to post
Share on other sites
http://www.phpfreaks.com/forums/index.php/topic,96689.msg387319.html#msg387319

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.