2011-08-11 97 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