cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: Newbie PHP/Curl Problem

From: Ken Harris <kharris_at_lhinfo.com>
Date: Mon, 3 Nov 2003 10:41:02 -0500

Based on what you have below, the command-line version should look something
like this:

curl --verbose --silent --location --max-time 3 --data "url=index%3Dbooks&field-
keywords=$isbn" http://www.amazon.com/exec/obidos/search-handle-form/002-
5640957-2809605

You may also need an "--referrer ;auto" to get the location following correct,
but the above seemed to work from the command-line.

From PHP you would do the following:

$cmd = 'curl --verbose --silent --location --max-time 3 --data "url=index%
3Dbooks&field-keywords=$isbn" http://www.amazon.com/exec/obidos/search-handle-
form/002-5640957-2809605';

exec ( $cmd, $arrResults, $nRetVal );

$arrResults is an array of the result variables.

$nRetVal is the numeric result code of the exec where 0 (zero) equals success.

Hope this helps

-- 
Ken Harris
Senior Consultant
http://www.lhinfo.com
(410) 597-8916
Quoting Alistair Ross <ali_at_woollyfoot.org>:
> Hi all,
> 
> I've written the following in PHP but my university aren't willing to
> install the curl module for PHP so i need to make an external call to the
> command line curl program. I've tried loads of ways but just can't get it
> to behave in the same way as my PHP script does.
> 
> The PHP is:
> 
> <?php
> 
>         $isbn="0446394319";
> 
>         // use curl to retrieve the search results
> 
>         $url =
> "http://www.amazon.com/exec/obidos/search-handle-form/002-5640957-2809605";
>         $ch = curl_init();    // initialize curl handle
>         #curl_setopt($ch, CURLOPT_VERBOSE, 1);
>         curl_setopt($ch, CURLOPT_URL, $url); // set url
>         curl_setopt($ch, CURLOPT_FAILONERROR, 1); // it had better not
> error!
>         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirection
> if url changes
>         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return it to a
> variable
>         curl_setopt($ch, CURLOPT_TIMEOUT, 3); // timeout of 3s just in case
>         curl_setopt($ch, CURLOPT_POST, 1); // set method to POST
>         curl_setopt($ch, CURLOPT_POSTFIELDS,
> "url=index%3Dbooks&field-keywords=$isbn"); // add search string to
> POST
>         $result = curl_exec($ch); // run the whole darn thing
>         curl_close($ch); // close curl handle
> 
>         echo $result;
> 
>         ?>
> 
> My attempts at the commandline code can't seem to follow the re-directs
> properly and end up just GETting the search input page.
> 
> Thanks in advance for your help.
> 
> Alistair
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive?  Does it
> help you create better code?   SHARE THE LOVE, and help us help
> YOU!  Click Here: http://sourceforge.net/donate/
> 
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Received on 2003-11-03