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

curl-and-php

RE: [Cookie] Handle a servlet session.

From: Fluteau Jerome ICM N PG U PLM A 2 <Jerome.Fluteau_at_icn.siemens.de>
Date: Thu, 17 Oct 2002 14:18:37 +0200

Hi Daniel,
 
FYI: I try to simulate the navigation within a site in order to post data
on several forms.
        First problem: send the username and password to get the login page.

        

=> First of all, when I test CURLOPT_COOKIEFILE, nothing seems to be written
in my cookie.txt. Is there
something wrong in this code (my username and password are within
$LOGINURL):

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, "C:\tmp\cookie.txt");
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_exec ($ch);
curl_close ($ch);

=> Concerning CURLOPT_FOLLOWLOCATION, I'm not sure to well understand how I
could use it. Indeed I tried
to make a simple request on another site (my mailbox) with my username and
password and it worked well, I got
the page after login, I didn't even need to use CURLOPT_FOLLOWLOCATION!
The problem is that the servlet from my work site doesn't give directly the
name of the login page as on my
mailbox, there is previously several requests:
 
.../servlet/oapdev?page=oap_fset_after_login.jsp
and then only:
.../eng/oap_fset_after_login.jsp
and then the 3 frames of the "after login page"...

The frames management is not a problem, all I have to do is to put the right
cookie in each request header.
CURLOPT_COOKIEJAR should be appropriate for this kind of work, if I succeed
in using it...;-)
 
=> Another little question:
Is it possible to make several request in only one curl_exec()? I'm mean
doing each request
with the previous cookie, to simulate a navigation until the right page. The
following code is surely wrong,
but you get the idea...;-)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$LOGINURL");
curl_setopt($ch, CURLOPT_COOKIEFILE, 0);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL,".../page1.jsp");
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL,".../page2.jsp");
curl_exec ($ch);
curl_close ($ch);

Besides is the code executed in the same order as the written code? In other
words, is the curl_setopts order important?

Thanks a lot.

-----Original Message-----
From: Daniel Stenberg [mailto:daniel_at_haxx.se]
Sent: Thursday, October 17, 2002 8:25 AM
To: curl and php list
Subject: Re: [Cookie] Handle a servlet session.

On Wed, 16 Oct 2002, Fluteau Jerome ICM N PG U PLM A 2 wrote:

> here is my problem: I want to post data on a jsp form, but before
accessing
> to the form I have to post an username and a password on a previous jsp
> login page. My problem is that when I post the username and password, I
> receive the same login page as previously, there is no link between the
log
> page and the "after login" page.

No? Usually sites pass a cookie back and a Location: header to the page it
wants you to do to after the login.

> The problem is to handle the servlet session I think (jsession_id in the
> header) but I don't exactly know how to do that yet.

Well, unfortunalely, we have different issues to deal with here. libcurl
itself allows pretty flexible ways to solve this, but AFAIK the PHP/CURL
module is not offering access to all those.

If there is a Location returned from the login post, then use FOLLOWLOCATION
and have COOKIEFILE set to a non-existing file (makes it read no cookies by
default but parse returened one). When following the Location, it'll use the
proper cookies in the subsequent request.

You should probably consider using the COOKIEJAR option to have the cookies
stored in a cookie file when the handle is closed, and then set that file
with COOKIEFILE on following requests, which makes them use the proper
cookies automaticly.

> The idea could be to get the jsession_id from the header when connecting
to
> the servlet server and then to add it in each request that I send. I try
to
> use CURLOPT_COOKIE, CURLOPT_COOKIEJAR,etc. but I have to test them to know
> exactly what they do.

CURLOPT_COOKIEJAR saves cookies in a file.
CURLOPT_COOKIEFILE reads cookies from a file
CURLOPT_COOKIE sets a cookie in a request.

> Do you think it is possible to handle a servlet session?

Oh sure. Been done a million times.

-- 
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
This sf.net email is sponsored by: viaVerio will pay you up to
$1,000 for every account that you consolidate with us.
http://ad.doubleclick.net/clk;4749864;7604308;v?
http://www.viaverio.com/consolidator/osdn.cfm
-------------------------------------------------------
This sf.net email is sponsored by: viaVerio will pay you up to
$1,000 for every account that you consolidate with us.
http://ad.doubleclick.net/clk;4749864;7604308;v?
http://www.viaverio.com/consolidator/osdn.cfm
Received on 2002-10-17