I am having a really strange issue that has been driving me mad for days. I am trying to follow a redirected affiliate link to using curl to then locate a product model number and return it to the database. This script works fine for normal links but not for the affiliate link. I assumed because of the redirect. I am now in a position where I seem to be stuck in a permanent loop when I am accessing the script and the page is never returned. here is an example link: http://pdt.tradedoubler.com/click?a(1394350)p(46927)prod(59715571)ttid(5) The really weird thing is that when I tried it on my office PC I get the loop, on my home PC it does actually function. The script is on my server so what possible effect could the PC have on redirects? It is baffling me and any help would be appreciated. here is some example code. 1. $sql = new mysqli('localhost', 'username', 'password', 'database'); 2. $qry = 'SELECT * FROM table where title is null'; 3. $res = $sql->query($qry); 4. $script_start = time(); 5. $ch = curl_init(); 6. 7. while($row = $res->fetch_object()) { 8. 9. //curl_redir_exec($ch); 10. curl_setopt($ch, CURLOPT_HEADER, true); 11. curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); 12. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 13. 14. 15. curl_setopt($ch,CURLOPT_URL, $row->url); 16. 17. $content = curl_exec($ch); 18. 19. } 20. echo $content; 21. curl_close($ch); Code (markup):
You can stop infinite loops by using CURLOPT_MAXREDIRS You could also add in a curl_error check and then break the loop if it exists. However, the way you have the loop, it is overwriting every curl data set in the while loop and then outputting the last 1 to the browser.