Re: [PHP] cURL & cookies

2006-04-26 Thread Eric Butera
On 4/25/06, Richard Lynch <[EMAIL PROTECTED]> wrote:Sounds to me like we have
different versions of cURL and yours is

> better. :-)
>
> Mine phpinfo() curl section has:
> libcurl/7.15.3 OpenSSL/0.9.7d zlib/1.2.1
>
> which would seem to be the most current version...
>
> Or, perhaps, the order in which you set the options matters?  Ick.
>
> For me, at least, the Cookie jar did not work until I took out the
> CURLOPT_HEADER, and it DID work after I changed that, and only that.
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
>
> Our production server uses this:
Php 4.4.0
CURL Information libcurl/7.15.1 OpenSSL/0.9.8a zlib/1.1.4

My local machine:
Php 4.3.11
CURL Information libcurl/7.10.5 OpenSSL/0.9.7i ipv6 zlib/1.2.3
(not by choice ;))


Re: [PHP] cURL & cookies

2006-04-25 Thread Richard Lynch
On Tue, April 25, 2006 11:50 am, Eric Butera wrote:
> On 4/25/06, Richard Lynch <[EMAIL PROTECTED]> wrote:Oh, and here's the
> REAL
> problem:
>
>>
>> If you use CURLOPT_HEADER, 1, then, like, for some reason beyond my
>> ken, the COOKIEJAR/COOOKIEFILE stuff just plain doesn't get done.

> On an application I was forced to write, the goal was to create an
> interface
> to another system on another server.  I used cURL to grab the pages.
> Their
> system sent three cookies and used tons of redirects to set their
> session
> and validate logins.  So basically I ended up with something like
> this:
>
> define('_COOKIEJAR', '/tmp/cjar_'. session_id());
> define('_COOKIEFILE', _COOKIEJAR);
>
> curl_setopt($curl, CURLOPT_COOKIEJAR, _COOKIEJAR);
> curl_setopt($curl, CURLOPT_COOKIEFILE, _COOKIEJAR);
> curl_setopt($curl, CURLOPT_HEADER, TRUE);
> curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);

> My point is that I have headers turned on and the cookie jar files get
> wrote
> to /tmp.  So am I misunderstanding that you said it is one or the
> other?
>
> Let me know if I'm wrong, thanks!

Sounds to me like we have different versions of cURL and yours is
better. :-)

Mine phpinfo() curl section has:
libcurl/7.15.3 OpenSSL/0.9.7d zlib/1.2.1

which would seem to be the most current version...

Or, perhaps, the order in which you set the options matters?  Ick.

For me, at least, the Cookie jar did not work until I took out the
CURLOPT_HEADER, and it DID work after I changed that, and only that.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] cURL & cookies

2006-04-25 Thread Eric Butera
On 4/25/06, Richard Lynch <[EMAIL PROTECTED]> wrote:Oh, and here's the REAL
problem:

>
> If you use CURLOPT_HEADER, 1, then, like, for some reason beyond my
> ken, the COOKIEJAR/COOOKIEFILE stuff just plain doesn't get done.
>
> This really sucks if you need *other* headers and want curl to manage
> the Cookies for you, but there it is.
>
> I'm not sure if I remembered to file a bug report on that or not...
>
> If the general conscensus on this list is that CURLOPT_HEADER "on"
> should not negate the use of CURLOPT_COOKIEFILE and/or
> CURLOPT_COOKIEJAR, then we may want to file a bug report...
>
> But I strongly suspect that bug report would most correctly go to
> curl, and not PHP, since I doubt that PHP does anything to screw this
> up -- it's probably all in curl itself, no?
>
> Or maybe me and Peter are the only 2 guys on the planet that think you
> should get to have both...
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> Richard,

On an application I was forced to write, the goal was to create an interface
to another system on another server.  I used cURL to grab the pages.  Their
system sent three cookies and used tons of redirects to set their session
and validate logins.  So basically I ended up with something like this:

define('_COOKIEJAR', '/tmp/cjar_'. session_id());
define('_COOKIEFILE', _COOKIEJAR);

curl_setopt($curl, CURLOPT_COOKIEJAR, _COOKIEJAR);
curl_setopt($curl, CURLOPT_COOKIEFILE, _COOKIEJAR);
curl_setopt($curl, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);

I'm sure this is all wrong, but it was all I could come up with. ;)

I have headers turned on so that I can parse them to get the header redirect
history so that I can track a sort of "browser history."  Curl just reported
the original url even though I was three redirects away from what curl
thinks it is.

My point is that I have headers turned on and the cookie jar files get wrote
to /tmp.  So am I misunderstanding that you said it is one or the other?

Let me know if I'm wrong, thanks!


Re: [PHP] cURL & cookies

2006-04-25 Thread Richard Lynch
On Sat, April 22, 2006 3:12 am, Peter Hoskin wrote:
> I'm trying to produce an sms sending script, however having problems
> with curl and storing cookies. The login page works fine, however the
> second http request returns a login page rather than authenticated
> content. Additionally, in the headers a different cookie value for
> JSESSIONID is set.
>
> I'm running PHP/5.1.2 on FreeBSD
>
> This script:
> define('COOKIEJAR','/path/to/curl-cookiejar');
> define('USERAGENT','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1)');
>
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
.
.
.
> $return['login'] = curl_exec($ch);
> curl_close($ch);
> unset($ch);
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);

Here,  you should also use CURLOPT_COOKIEJAR and COOKIEJAR, in case
you get some *MORE* cookies on subsequendc pages.

In fact, go ahead and just use both options all the time -- assuming
your COOKIEFILE starts off empty.

Or perhaps you should http://php.net/unlink it at the beginning.

> $fp = fopen(COOKIEJAR,'w');
> fclose($fp);

Ah.

This is to wipe out the COOKIEJAR when you're done, right?...

If not, get rid of it.

Oh, and here's the REAL problem:

If you use CURLOPT_HEADER, 1, then, like, for some reason beyond my
ken, the COOKIEJAR/COOOKIEFILE stuff just plain doesn't get done.

This really sucks if you need *other* headers and want curl to manage
the Cookies for you, but there it is.

I'm not sure if I remembered to file a bug report on that or not...

If the general conscensus on this list is that CURLOPT_HEADER "on"
should not negate the use of CURLOPT_COOKIEFILE and/or
CURLOPT_COOKIEJAR, then we may want to file a bug report...

But I strongly suspect that bug report would most correctly go to
curl, and not PHP, since I doubt that PHP does anything to screw this
up -- it's probably all in curl itself, no?

Or maybe me and Peter are the only 2 guys on the planet that think you
should get to have both...

-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] cURL & cookies

2006-04-22 Thread Peter Hoskin
Hi,

I'm trying to produce an sms sending script, however having problems
with curl and storing cookies. The login page works fine, however the
second http request returns a login page rather than authenticated
content. Additionally, in the headers a different cookie value for
JSESSIONID is set.

I'm running PHP/5.1.2 on FreeBSD

This script:
define('COOKIEJAR','/path/to/curl-cookiejar');
define('USERAGENT','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');


$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
curl_setopt($ch, CURLOPT_URL,
"https://www.domain.com/cocoon/nonav/secureLogin/login.xml";);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array2urlstring($logindata));
curl_setopt($ch, CURLOPT_NOBODY, 1);
$return['login'] = curl_exec($ch);
curl_close($ch);
unset($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_URL,
"https://www.domain.com/cocoon/websms/websms.xml";);
$return['sms'] = curl_exec($ch);
curl_close($ch);
unset($ch);

$fp = fopen(COOKIEJAR,'w');
fclose($fp);

echo "Login\n";
echo "\n";
echo htmlspecialchars($return['login']);
echo "\n";

echo "SMS\n";
echo "\n";
echo $return['sms'];
echo "\n";

Produces the output:


  Login

HTTP/1.0 200 OK
Date: Sat, 22 Apr 2006 08:04:03 GMT
Server: Apache/1.3.33 (Unix) mod_jk/1.2.15 mod_perl/1.29 mod_ssl/2.8.22
OpenSSL/0.9.7e
Set-Cookie: JSESSIONID=FC9D098E63E5A065AC8934B7F7BB605A.zooapp02b;
Path=/cocoon; Secure
Set-Cookie: user=; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
X-Cocoon-Version: 2.1.5.1
Connection: close
Content-Type: text/html



  SMS

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Sat, 22 Apr 2006 08:04:03 GMT
Content-Type: text/html
Connection: close
Set-Cookie: AlteonP=c3b503cb52f50428; path=/
Server: Apache/1.3.33 (Unix) mod_jk/1.2.15 mod_perl/1.29 mod_ssl/2.8.22
OpenSSL/0.9.7e
Set-Cookie: JSESSIONID=56D23CCA63E2DDE37293FB64647027D8.zooapp01b;
Path=/cocoon
Set-Cookie: user=; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
X-Cocoon-Version: 2.1.5.1
Via: 1.1 nsw-cache1 (NetCache NetApp/6.0.2)

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



Re: [PHP] Curl & cookies

2004-05-09 Thread Curt Zirzow
* Thus wrote Jason Morehouse ([EMAIL PROTECTED]):
> Has anyone tried using curl to fetch a web page and cookies?
> 
>  $ch = curl_init();
> curl_setopt ($ch, CURLOPT_URL, 'http://www.php.net');
> curl_setopt ($ch, CURLOPT_HEADER, 0);
> curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt ($ch, CURLOPT_COOKIEJAR,'cookie.txt');
> curl_setopt ($ch, CURLOPT_COOKIE,1);
> $content = curl_exec ($ch);
> curl_close ($ch);
> $cookie = file_get_contents('cookie.txt');
> print $cookie;
> ?>
>
> 
> This works fine, and the cookie gets stored in the cookie.txt file, but it
> only ever returns 1 cookie.  There should be 2 for php.net.  Same with
> pretty much any other site.  Are there any configuration items I'm missing
> for the cookie jar?

php's front page will only set one cookie, only in certain
conditions will it set other cookies. I have 4 total from php.net:
  LAST_SEARCH, MYPHPNET, LAST_LANG, COUNTRY

php only set's one cookie on the front page.


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

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



[PHP] Curl & cookies

2004-05-09 Thread Jason Morehouse
Has anyone tried using curl to fetch a web page and cookies?



$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://www.php.net');
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIE,1);
$content = curl_exec ($ch);
curl_close ($ch);
$cookie = file_get_contents('cookie.txt');
print $cookie;
?>


This works fine, and the cookie gets stored in the cookie.txt file, but it
only ever returns 1 cookie.  There should be 2 for php.net.  Same with
pretty much any other site.  Are there any configuration items I'm missing
for the cookie jar?


--
Jason Morehouse ([EMAIL PROTECTED])
Netconcepts LTD - Auckland, New Zealand
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php