newbie cURL quesion

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Trying to learn from:">

The code in this article doesn't work and I wondered how to fix it?
See below - thanks.

$url =
"( product link shortened)";">( product link shortened)";
$ch = curl_init();    // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS,
"url=index%3Dbooks&field-keywords=PHP+MYSQL"); // add POST fields
$result = curl_exec($ch); // run the whole process
echo $result;

Re: newbie cURL quesion

Probably the exentsion is not included!
It's a good idea to turn on all the error report,
so you can see what's wrong with the code. You can use the
following in your code or permanently change the php.ini file

    error_reporting( E_ALL );

Excerpt from the manual:
A note about curl_init (and all other curl functions as well.) If when you
try to use the function a compile error comes up 'unknown function' then you
need to load the dll. You'll find a ton of documentation about how to do
this, but the absolute easiest way is to update to the newest version of
php. If you download the full binary, there are included many extension
dlls. All you need do then is 'un-comment' the extension = php_curl.dll
under dynamic extensions section, set you extesions directory to a valid
location ([probably c:/php/extensions) and copy the ssleay32.dll files and
libeay32.dll files to your working OS directory (system32 in windows, don't
know UNIX sorry.) This literally takes, after download,2 minues!

Quoted text here. Click to load it

Re: newbie cURL quesion

Also, put this after your curl_exec line since I found out the hard way php
doesn't report the curl problems. I think on mine we had it compiled into
php so the function was there (See Duyet's post below) but it wasn't set up
correctly in Apache.

if(curl_errno($ch) > 0) echo "<p style='color: red'><b>cURL ERROR
#".curl_errno($ch).": ".curl_error($ch)." at ".__LINE__." in


Quoted text here. Click to load it
"( product link shortened)";">( product link shortened)";
Quoted text here. Click to load it

Site Timeline