淘宝客链接转换

2015/10/23 posted in  脚本
Tags:  #php

date: 2015-10-23 15:43

工作需要,转换淘宝链接

$refer =  $header['Location'];

$tu = explode("tu=",$refer);
$tu = $tu['1'];
$url = urldecode($tu);

$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_REFERER, $refer);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
   
$result = curl_exec($ch);
$errno  = curl_errno($ch);
$infos = curl_getinfo($ch); 
    
curl_close($ch);
$h = $infos['redirect_url'];
echo $h; //淘宝链接