卷曲到达网址,但服务器未接收到数据

时间:2018-10-06 10:48:17

标签: php curl

有人可以帮助我吗?我想使用curl访问网站。
我的代码如下:

$data = array(
    'utm_source'=>'Google',
    'utm_medium'=>'Google',
    'utm_campaign'=>'Sales',
    'utm_term'=>'united flights tickets'
);
$data = http_build_query($data, '', '&');
$proxies[] = 'user:password@71.6.46.151:443';
$proxies[] = 'user:password@14.102.19.206:61217';
$proxies[] = 'user:password@187.95.230.65:8080';
$url = 'https://www.example.com/index.php?'.$data;

$ch = curl_init();

if (isset($proxy)) { // If the $proxy variable is set, then
    curl_setopt($ch, CURLOPT_PROXY, $proxy); // Set CURLOPT_PROXY with proxy in $proxy variable
}

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:5.0)    Gecko/20100101 Firefox/5.0');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com');
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_URL, $url);

$results = curl_exec($ch);  // Execute a cURL request

if (curl_error($ch)) {
    $error_msg = curl_error($ch);
}

$info = curl_getinfo($ch);
curl_close($ch);

print_r($error_msg);
print_r($info);
print_r($results);

它访问了网站并且也显示在Google Analytics(分析)帐户中,但是唯一的问题是,引用者和来源在Google Analytics(分析)中显示“直接”。
如果还有其他方法可以实现,请告诉我。

0 个答案:

没有答案