Alistair Ross | 3 Nov 2003 16:23

Newbie PHP/Curl Problem

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
(Continue reading)

Daniel Stenberg | 3 Nov 2003 16:35
Picon
Favicon

Re: Newbie PHP/Curl Problem

On Mon, 3 Nov 2003, Alistair Ross wrote:

> My attempts at the commandline code can't seem to follow the re-directs
> properly and end up just GETting the search input page.

So what command line did you try?

Use -L to follow redirects and -d to send the POST.

BTW, the curl-users might be a better list to get advice on using the curl
tool...

--

-- 
 Daniel - been obfuscating curl source code since 1998.
 [[ Do not post private mails to this email address. They won't reach me. ]]

-------------------------------------------------------
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/

Ken Harris | 3 Nov 2003 16:41

Re: Newbie PHP/Curl Problem

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

(Continue reading)

Alistair Ross | 3 Nov 2003 16:53

Re: Newbie PHP/Curl Problem

I was trying:

curl -vL -d "url=index%3Dbooks&field-keywords=0446394319" -o
/tmp/temp.html
http://www.amazon.com/exec/obidos/search-handle-form/002-5640957-2809605

and it seems to just get amazon's error page.

> On Mon, 3 Nov 2003, Alistair Ross wrote:
>
>> My attempts at the commandline code can't seem to follow the re-directs
>> properly and end up just GETting the search input page.
>
> So what command line did you try?
>
> Use -L to follow redirects and -d to send the POST.
>
> BTW, the curl-users might be a better list to get advice on using the curl
> tool...
>
> --
>  Daniel - been obfuscating curl source code since 1998.
>  [[ Do not post private mails to this email address. They won't reach me.
> ]]
>
>
> -------------------------------------------------------
> 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
(Continue reading)

Nick Manoleras | 4 Nov 2003 00:36
Picon
Favicon

Sending multiple files

OS: Windows XP
Compiler: Microsoft visual C++

I'm new to LibCurl and I hope this isn't a stupid question.

I have written a small application using LibCurl to automatically send files
(ftp) as they are stored in a particular directory. The code is based on the
ftpput.c sample.
At present a separate ftp session is initiate for each file. How do I code
the use of one session to send multiple file (if possible).

Thanks

Nick Manoleras.

-------------------------------------------------------
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/

Daniel Stenberg | 4 Nov 2003 08:17
Picon
Favicon

Re: Sending multiple files

On Tue, 4 Nov 2003, Nick Manoleras wrote:

> I'm new to LibCurl and I hope this isn't a stupid question.

You did post this question on the 'curl and php list', which seems a bit odd
if it has nothing to do with PHP. I would recommend subscribing to and using
curl-library instead, it is where other libcurl-hackers hang out.

> I have written a small application using LibCurl to automatically send files
> (ftp) as they are stored in a particular directory. The code is based on the
> ftpput.c sample.
> At present a separate ftp session is initiate for each file. How do I code
> the use of one session to send multiple file (if possible).

You use the same easy handle for every curl_easy_perform() call. libcurl will
then attempt to re-use connections as often as possible. If you upload
multiple files to the same host and port number, libcurl will re-use the
single connection every time.

Do note however that FTP will always require and setup a second connection for
the data to transfer, and that connection cannot be re-used but will be setup
and taken down once for each file transfer. This is by design and restricted
by how the protocol works, nothing libcurl can do anything about.

--

-- 
 Daniel - been obfuscating curl source code since 1998.
 [[ Do not post private mails to this email address. They won't reach me. ]]

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
(Continue reading)

Sear, Mick | 4 Nov 2003 10:12
Picon

Question about undocumented PHP functions

I'm new to cUrl, but already it's proving really useful, but documentation
is a bit sparse.  I'm using cUrl to spider a site, and so might have an
issue with timeouts (I'm running in Safe Mode).

I noticed there are functions called curl_multi_* etc., but there's no
documentation.  Can anyone point me in the right direction?  These might
help avoid timeouts if I can simultaneously form several HTTP requests.

Thanks in advance,
Mick

-------------------------------------------------------
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/

Daniel Stenberg | 4 Nov 2003 10:38
Picon
Favicon

Re: Question about undocumented PHP functions

On Tue, 4 Nov 2003, Sear, Mick wrote:

> I noticed there are functions called curl_multi_* etc., but there's no
> documentation.

There are PHP-functions for that? The C interface covering the multi functions
are documented and one access-point to its documentation is here:

	http://curl.haxx.se/libcurl/c/libcurl-multi.html

But take note that this document is NOT covering the PHP interface, only the
underlying libcurl.

--

-- 
 Daniel - been obfuscating curl source code since 1998.
 [[ Do not post private mails to this email address. They won't reach me. ]]

-------------------------------------------------------
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/

beshoo | 4 Nov 2003 13:27

session and NO cookies

HI all

I have a problem with this case :

i have a asp page this page need a user name and password 

this page just use the session and there is NO cookies used 

and when I pass the username and password it will redirect me to other
page

by using this :

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);

cos if not I will have Object Move

I tried to use 

curl_setopt($ch,CURLOPT_COOKIE,"");

when I test the script  it just redirect me to the login.asp again .

please help .

no luck …..

OS: Linux

Scripting lang. : PHP
(Continue reading)

Daniel Stenberg | 4 Nov 2003 13:42
Picon
Favicon

Re: session and NO cookies

On Tue, 4 Nov 2003, beshoo wrote:

> i have a asp page this page need a user name and password this page just use
> the session and there is NO cookies used

What is "the session"? That's not a term I'm familiar with. Can you show us
with HTML and HTTP headers?

> and when I pass the username and password it will redirect me to other page
>
> by using this :
>
> curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
>
> cos if not I will have Object Move

Of course, as that's how curl is set to work.

> I tried to use
>
> curl_setopt($ch,CURLOPT_COOKIE,"");

Why? What's that supposed to do for you?

> when I test the script it just redirect me to the login.asp again .

And what can we do to help you fix this? You probably don't login to the login
page properly, the site detects that and sends you back to retry.

If you don't tell us details, we can't help you with details.
(Continue reading)


Gmane