开发者

How can I set curl_init to a variable?

I'm trying to create a line like this, in PHP:

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

I'm doing this so I can set options for $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

Why can开发者_开发知识库't I set $cURL (it gives me an error on that line), and is there any way around it?


Don't use $ before curl_init:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜