curl-and-php
Re: Sending a Session/Cookie in the Request
Date: Fri, 21 Nov 2003 08:48:59 +0100 (CET)
On Thu, 20 Nov 2003, John Napoleone wrote:
> >From the command line it looks like this:
>
> curl -d "database=databaseName&agent_number=number&pswd=000000" –b cookies
> -c cookies.txt -e https://secure.website.net/shop/logon.asp -i -v
> https://secure.website.net/shop/main.asp
> https://secure.website.net/shop/search.asp?item=155
>
> In PHP my code looks like this:
>
> $ch = curl_init ();
> curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
You didn't do these from the command line.
> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS,
> “database=databaseName&agent_number=number&pswd=000000");
> curl_setopt($ch, CURLOPT_REFERER,
> “https://secure.website.net/shop/logon.asp ");
> curl_setopt($ch, CURLOPT_HEADER, 1);
> curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
> curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
> curl_setopt($ch, CURLOPT_VERBOSE, 1);
> curl_setopt($ch, CURLOPT_URL, "https://secure.website.net/shop/main.asp ");
> curl_setopt($ch, CURLOPT_URL,
> " https://secure.website.net/shop/search.asp?item=155");
You cannot set two URLs. You need to set one, do an *exec() call, then set the
next and do another *_exec() call.
> HEADER: Set to retrieve the Header data which contains the very important
> Session/Cookie that I need to send back on the subsequent and final request
> (main.asp => search.asp)
No need to set this option for that purpose. Since you specify the cookiejar
option, it'll take care of all the cookies automaticly-
> VERBOSE: Set to display what cURL is doing, which by the way does not work
> in PHP for some reason, but was very useful when working from the command
> line.
I can figure out why, but I would still say that this is a bug in the PHP/CURL
code.
> I believe that for some reason the Cookie with the Session value is not
> being sent to search.asp
Correct, since it won't attempt to fetch the first URL. Only the second one
will be fetched.
I hope this helps.
-- Daniel Stenberg -- http://curl.haxx.se/ -- http://daniel.haxx.se/ [[ 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/Received on 2003-11-21