...

View Full Version : Please help me understand this CURL_SETOPT_ARRAY() error.



mOrloff
01-08-2010, 09:41 PM
I'm getting this error:Warning: curl_setopt_array() [function.curl-setopt-array]: Array keys must be CURLOPT constants or equivalent integer values in /home/voyager1/public_html/test.php on line 74
What I understand from the error is that all the associated array keys must be like "CURLOPT...", but I must be wrong there, because they all appear to meet that criteria.

Here's my code


$ch=curl_init(); // initiallize a curl session
$url='https://www.example.com/login.htm'; // define the target URI
$options=array( CURLOPT_URL=>$url,
CURLOPT_REFERRER=>$url,
CURLOPT_USERAGENT=>'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5)',
CURLOPT_RETURNTRANSFER=>1,
CURLOPT_CONNECTTIMEOUT=>2,
CURLOPT_POST=>1,
CURLOPT_POSTFIELDS=>'org=value&login=user&pwd=password',
CURLOPT_COOKIEJAR=>'cookies.txt',
CURLOPT_COOKIEFILE=>'cookies.txt'
);
curl_setopt_array($ch,$options); // <-- THIS IS LINE 74


What am I missing ??

~ Mo

Fou-Lu
01-08-2010, 10:39 PM
CURLOPT_REFERRER is spelled wrong. Well, wrong with PHP anyway, for whatever reason referrer has been mis-spelled as referer and has kept going all of this time. I think apache is the cause of this one.


Oh yes, btw, just because it has CURLOPT in its definition doesn't mean its a part of the curl library. What they mean is that it needs to be a constant used specifically for CURL, which generally have the CURLOPT as its prefix. It could be called MYAWESOMECONNECTORCONSTANTPREFIX if you wanted it to be, as long as it matches the value for what curlopt expects. This is because PHP does not support enums (sadly).

mOrloff
01-08-2010, 11:22 PM
CURLOPT_REFERRER is spelled wrong...
Thanks.
:thumbsup:

...
Oh yes, btw, just because it has CURLOPT in its definition doesn't mean its a part of the curl library. What they mean is that it needs to be a constant used specifically for CURL...

Thanks for the info.
I now understand what it's saying.

~ Mo



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum