Here's my code:
$urls = array('http://www.avantlink.com/click.php?p=62629&pw=18967&pt=3&pri=152223&tt=df');
$curl_multi = curl_multi_init();
$handles = array();
$options = $curl_options + array(
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOBODY => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADERFUNCTION => 'read_header',
CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36',
CURLOPT_HTTPHEADER => array(
'Accept-Language: en-US,en;q=0.8',
'Accept-Encoding: gzip,deflate,sdch',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Connection: keep-alive',
'Host: www.avantlink.com',
));
foreach($urls as $i => $url) {
$handles[$i] = curl_init($url);
curl_setopt_array($handles[$i], $options);
curl_multi_add_handle($curl_multi, $handles[$i]);
}
$active = null;
do {
$status = curl_multi_exec($curl_multi, $active);
sleep(1);
error_log('loading redirect: '.$active.' left');
}
while (!empty($active) && $status == CURLM_OK);
do {
$status = curl_multi_exec($curl_multi, $active);
} while ($status == CURLM_CALL_MULTI_PERFORM);
while ($active && ($status == CURLM_OK)) {
if (curl_multi_select($curl_multi) != -1) {
do {
$status = curl_multi_exec($curl_multi, $active);
} while ($status == CURLM_CALL_MULTI_PERFORM);
}
}
if ($status != CURLM_OK) {
trigger_error("Curl multi read error $status\n", E_USER_WARNING);
}
$results = array();
foreach($handles as $i => $handle) {
$results[$i] = curl_getinfo($handle);
curl_multi_remove_handle($curl_multi, $handle);
curl_close($handle);
}
curl_multi_close($curl_multi);
Here's what it gets me (from the read_header() function):
HTTP/1.1 200 OK
Date: Mon, 18 Nov 2013 22:42:29 GMT
Server: Apache
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
If I print_r() the curl_getinfo() I get this:
Array
(
[url] => http://www.avantlink.com/click.php?p=62629&pw=18967&pt=3&pri=152223&tt=df
[content_type] => text/html; charset=utf-8
[http_code] => 200
[header_size] => 247
[request_size] => 402
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 2.391713
[namelookup_time] => 0.388584
[connect_time] => 1.389628
[pretransfer_time] => 1.389645
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 20
[upload_content_length] => 0
[starttransfer_time] => 2.391203
[redirect_time] => 0
[certinfo] => Array
(
)
)
But if you go to that URL in chrome (or whatever) you'll see that the URL gives you a 302 redirect to http://www.alssports.com/product.aspx?pf_id=10212312&avad=18967_b55919f9. I need it to give me the alssports.com url. I've been working on this code for almost the entire day. What am I doing wrong?