PHP, Curl and redirect loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ollyno1uk
Forum Newbie
Posts: 1
Joined: Fri Oct 05, 2007 3:24 am

PHP, Curl and redirect loop

Post by ollyno1uk »

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(139 ... 71)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.

Code: Select all

$sql = new mysqli('localhost', 'username', 'password', 'database');
$qry = 'SELECT * FROM table where title is null';
$res = $sql->query($qry);
$script_start = time();
$ch = curl_init();
 
while($row = $res->fetch_object()) {
    
    //curl_redir_exec($ch);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
 
    
    curl_setopt($ch,CURLOPT_URL, $row->url);
    
    $content = curl_exec($ch);
    
}
echo $content;
curl_close($ch);
Post Reply