2011-08-11 63 views
0

我想创建这样一条线,在PHP中:如何将curl_init设置为变量?

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

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

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(它给了我一个错误),有没有办法绕过它?

回答

3

curl_init之前,不要使用$:

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

的工作,谢谢!加 - 我觉得自己像个白痴。的xD – Alper