0

I'm trying to get links from some websites by using Simple Html Dom,(file_get_content)

The problem is that some of these links use a redirect to the actual post, my script follows it all the way to the post but on my website where I link to that post I dont want php to echo out the file "process.php?id=121" but I want it to return the true actual url like "domain.com/redirected-to-here.html"

script looks something like

$html = file_get_html('www.domain.com/post/this-is-a-post.html');
foreach($html->find('div#post a',0) as $linktopost){
    echo $linktopost->href;
}

but this returns something like

www.domain.com/redirect.php?id=10

So the question actually is, how can I return the url by using Simple html dom parser AFTER it has been redirected?

Thanks in advance.

rokkz
  • 179
  • 1
  • 1
  • 13
  • This might be helpful: http://stackoverflow.com/questions/3799134/how-to-get-final-url-after-following-http-redirections-in-pure-php – puelo Oct 29 '13 at 22:51
  • thx for the answer but I already seen this one, cant do it this way with simple_html_dom :( – rokkz Oct 29 '13 at 22:53

1 Answers1

0

I'd use cURL and parse the location header with regex.

$ch = curl_init('www.domain.com/post/this-is-a-post.html');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$header_and_html = curl_exec($ch);
preg_match(...);