Re: [PHP] I need help with PHP, cURL, and POST

2007-01-03 Thread Richard Lynch
On Tue, January 2, 2007 8:56 pm, Charley wrote:
> What do you mean about the submit input?  I
> thought that was just a text link to cause
> the form to be submitted when clicked.  I
> didn't know that it sent anything to the
> server.  (As you can tell, I don't know
> anything about asp except what it stands
> for.)



This line in HTML, with variations, *WILL* send another &submit=Submit
as part of the HTTP request.

If you don't send that part, ASP scripts will puke on your pretty blue
suede shoes, more often than not, in my experience.

Never mind that Netscape 2 didn't send this field when you hit "Enter"
instead of actually clicking the button for a one-button form (default
action: submit).  MS never cared about interoperability then, and they
don't now, and I don't expect them to ever care in the future, no
matter how many times they claim to "embrace and extend" (or whatever
their slogan is this week).

> The paymentidfilter is a legitimate field,
> and works in the form and in the GET version
> of the cURL stuff.

Okay -- It just wasn't in the FORM, so wanted to check.

> It seems that e-gold has as its error
> response to send the login page for whatever
> one is asking for.  This is not very helpful
> (at least to me).

Oh, but it's *VERY* helpful.

It tells you that you are not "proving" to the server that you are a
legitimate logged-in user.

Which, in turn, means that somehow you need to do just that -- Fool
their server into accepting and maintaining your login credentials.

What this usually entails is something like this:

$curl = curl_init();

//login:
curl_setopt(CURLOPT_URL, ".../login.asp");
curl_setopt(CURLOPT_POSTDATA, "username=foo&password=bar");
curl_setopt(CURLOPT_COOKIEJAR,
"/full/path/to/php/writable/cookie/storage/file.txt");
curl_setopt(CURLOPT_COOKIEFILE,
"/full/path/to/php/writable/cookie/storage/file.txt");

//get data we actually want
//the script you currently have gets pasted in here

> I'll see if I can get this LiveHTTPheaders
> thing for firefox, since firefox is my main
> browser.
>
> From what I read, the cookie jar and file
> options take the name of the same file as
> their arguments.  Is there any path
> information that is required?  Can I just use
> something like "mycookies.txt" or must it
> have a specific extension?

The only restriction is that it MUST be readable/writable by the User
php runs as, so that PHP can write down the cookies it gets, and spit
them back to "prove" that it is still a valid user.

You also cannot use the COOKIE(JAR|FILE) with the CURLOPT_HEADER
option that lets you see the other headers. :-(  If you need the other
headers, you have to manage the cookies on your own instead of letting
curl do it for you.  This is not all that tricky, really, once you
look at what a Cookie actually looks like in the headers.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] I need help with PHP, cURL, and POST

2007-01-02 Thread Richard Lynch
On Tue, January 2, 2007 9:23 am, Charley wrote:
> 
...
> 
> */
>
> $pf = "AccountID=XX";
...
> $pf .= "&paymentidfilter=";

You are missing the "Submit" input, and ASP being ASP, it probably was
programmed to expect it, and will puke without it.

You also have added a paymentidfilter parameter that was not in the
original.  You may not be allowed to have that in the POST, perhaps.

>
> $ch = curl_init();

...
> echo "curlerror=" . curl_error($ch);

Based on the rest of your excellent post, you probably have no error
output here, but to be pedantic...  Are there any error messages here?

You may also want to turn off the FOLLOWLOCATION and dump out whatever
responses as the come, and then build up another query to follow the
re-directs by hand.  This will sometimes lead you to find out that
there are, for example, cookies flying back and forth that you need to
track (CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE) or something similar.

You may also want to provide some extra headers to make curl look more
like a "real" browser to fool any anti-web-scraping features in their
ASP script.

Compare output with Firefox LiveHTTPHeaders (?) and what curl is
giving you to find clues/differences that might indicate what to try
next.

Keep in mind that your goal is to make your curl script
indistinguishable to e-gold from a "real" user.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] I need help with PHP, cURL, and POST

2007-01-02 Thread Ligaya A. Turmelle
Have you looked at this tutorial -
http://devzone.zend.com/node/view/id/1081

It has an example specifically for how to use curl with POST

Respectfully,
Ligaya Turmelle

-Original Message-
From: Charley [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 03, 2007 1:24 AM
To: php-general@lists.php.net
Subject: [PHP] I need help with PHP, cURL, and POST

I am an experienced programmer who is just learning php and curl.

I have tried for several days to figure out how to use curl with POST to
get history information from e-gold.

The following script, which I guess uses GET works when   
have appropriate stuff in them.

But no matter what I have tried, and whose examples I have followed I
cannot get this to work with CURLOPT_POST set to true with what I think
is the appropriate information supplied.

I am testing this from XAMPP 1.5.5 on a Windows XP system, and the SSL
stuff and everything I think I need is present and seems to be working
fine.

The commented out form also works, so I guess e-gold will accept POSTed
data.

I just do not know how to get curl to send it for me or what options I
need to make it work.

Would someone be interested in showing me exactly what I need to modify
this script to work with POST?

https://www.e-gold.com/acct/historycsv.asp"; method="post">
   */

$pf = "AccountID=XX";
$pf .= "&PassPhrase=YYY";
$pf .= "&startmonth=12";
$pf .= "&startday=1";
$pf .= "&startyear=2006";
$pf .= "&endmonth=12";
$pf .= "&endday=31";
$pf .= "&endyear=2006";
$pf .= "&paymentsreceived=1";
$pf .= "&fees=1";
$pf .= "&paymentidfilter=";

$ch = curl_init();

// Follow any Location headers
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$url='https://www.e-gold.com/acct/historycsv.asp?' . $pf;
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch,
CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch,
CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_HEADER, FALSE);

$data=curl_exec($ch);
$info=curl_getinfo($ch);
echo "curlerror=" . curl_error($ch);
curl_close($ch);
echo "data=";
var_dump($data);
echo "info=";
var_dump($info);
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] I need help with PHP, cURL, and POST

2007-01-02 Thread Jochem Maas
Charley wrote:
> I am an experienced programmer who is just learning php and curl.
> 

...

> 
> Would someone be interested in showing me exactly what I need to modify this 
> script to work with POST?

the interest is 10%/week ;-) ... read on ...

> 
>   session_start();
> /*
> https://www.e-gold.com/acct/historycsv.asp"; method="post">
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> */
> 
> $pf = "AccountID=XX";
> $pf .= "&PassPhrase=YYY";
> $pf .= "&startmonth=12";
> $pf .= "&startday=1";
> $pf .= "&startyear=2006";
> $pf .= "&endmonth=12";
> $pf .= "&endday=31";
> $pf .= "&endyear=2006";
> $pf .= "&paymentsreceived=1";
> $pf .= "&fees=1";
> $pf .= "&paymentidfilter=";
> 

you don't want/need the GET query in $pf ...
instead something like this needs to be used (AFAIK):

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'AccountID'  => 'X',
'PassPhrase' => 'XX',
/* etc, etc */
));

refer to http://php.net/curl for more info.

this assumes that e-gold does accept POST as a request method
(which you test form seems to indicate it does)

> $ch = curl_init();
> 
> // Follow any Location headers
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
> $url='https://www.e-gold.com/acct/historycsv.asp?' . $pf;
> curl_setopt($ch, CURLOPT_URL, $url);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> 
> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
> curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
> curl_setopt($ch, CURLOPT_HEADER, FALSE);
> 
> $data=curl_exec($ch);
> $info=curl_getinfo($ch);
> echo "curlerror=" . curl_error($ch);
> curl_close($ch);
> echo "data=";
> var_dump($data);
> echo "info=";
> var_dump($info);
> ?>
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php