如何将curl_init设置为变量?

时间:2011-08-11 02:51:00

标签: php

我正在尝试用PHP创建这样的一行:

$cURL = $curl_init('http://mysite.com/2');

我这样做,所以我可以为$ cURL设置选项...

curl_setopt($cURL, CURLOPT_PROXY, $proxy); // proxy
curl_setopt($cURL, CURLOPT_PROXYPORT, $port); // proxy port
curl_setopt($cURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // use authentication
curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers); // send the headers
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); // We need to fetch something from a string, so no direct output!
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, 1); // we get redirected, so follow
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($cURL, CURLOPT_UNRESTRICTED_AUTH, 1); // always stay authorised
$wrong = curl_exec($cURL); // Get it
curl_close($cURL); // Close the curl stream

为什么我不能设置$ cURL(它在该行上给我一个错误),并且有什么方法可以解决它吗?

1 个答案:

答案 0 :(得分:3)

请勿在curl_init之前使用$:

$cURL = curl_init('http://mysite.com/2');