# Newbie - mechanize multiple cookies problem with form login

**URL:** <https://www.ruby-forum.com/t/newbie-mechanize-multiple-cookies-problem-with-form-login/116330>\
**Category:** Ruby\
**Created:** [October 4, 2007, 3:01pm UTC](https://www.ruby-forum.com/t/newbie-mechanize-multiple-cookies-problem-with-form-login/116330 "2007-10-04T15:01:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![friofool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6de8d8/32.png) [@friofool](https://www.ruby-forum.com/u/friofool)\
**Post date:** [October 4, 2007, 3:01pm UTC](https://www.ruby-forum.com/t/newbie-mechanize-multiple-cookies-problem-with-form-login/116330/1 "2007-10-04T15:01:48Z")

</div>

hi,

i’m just starting to work with this incredible tool…

but i got a first problem with the login process

i’m logging on my app like this :

* * *

@agent = WWW::Mechanize.new { |a| a.log = Logger.new(“mech.log”) }

@agent.user\_agent\_alias = ‘Mac Safari’  
@page = @agent.get(“[http://myappAdress/](http://myappAdress/)”)

@form = @page.forms.first

@form[‘form\_login’] = ‘myLog’  
@form[‘form\_password’] = ‘myPass’

@page = @agent.submit(@form, @form.buttons.first)

put @page.body

* * *

Identification process is done , i can see it in my application log, but  
the page displayed is still the login form.

here is the mechanize log .

* * *

Net::HTTP::Get: /  
request-header: accept-language =\> en-us,en;q0.5  
request-header: connection =\> keep-alive  
request-header: accept =\> _/_  
request-header: accept-encoding =\> gzip,identity  
request-header: user-agent =\> Mozilla/5.0 (Macintosh; U; PPC Mac OS X;  
en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3  
request-header: accept-charset =\> ISO-8859-1,utf-8;q=0.7,_;q=0.7  
request-header: keep-alive =\> 300  
Read 519 bytes  
Read 935 bytes  
Read 1959 bytes  
Read 2375 bytes  
Read 3399 bytes  
Read 3803 bytes  
response-header: connection =\> close  
response-header: p3p =\> CP=‘OTI DSP COR NID STP UNI OTPa OUR’  
response-header: content-type =\> text/html; charset=utf-8  
response-header: x-powered-by =\> PHP/5.1.6  
response-header: date =\> Thu, 04 Oct 2007 10:34:40 GMT  
response-header: server =\> Apache/2.2.4 (Fedora)  
response-header: content-length =\> 3803  
response-header: set-cookie =\>  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D;  
expires=Sun, 01-Oct-2017 10:34:40 GMT,  
pmv\_ck\_session=YToyOntzOjU6ImxvZ2luIjtzOjk6ImFub255bW91cyI7czo4OiJwYXNzd29yZCI7YjowO30%3D;  
expires=Thu, 04-Oct-2007 11:34:40 GMT  
saved cookie:  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D  
saved cookie:  
pmv\_ck\_session=YToyOntzOjU6ImxvZ2luIjtzOjk6ImFub255bW91cyI7czo4OiJwYXNzd29yZCI7YjowO30%3D  
status: 200  
query:  
“form\_login=myLog&form\_password=myPass&form\_url=http%3A%2F%2FmyAppUrl%2F&submit=Login+%3F”  
Net::HTTP::Post: /index.php?mod=login  
using cookie:  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D  
request-header: accept-language =\> en-us,en;q0.5  
request-header: connection =\> keep-alive  
request-header: accept =\> /  
request-header: accept-encoding =\> gzip,identity  
request-header: user-agent =\> Mozilla/5.0 (Macintosh; U; PPC Mac OS X;  
en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3  
request-header: content-type =\> application/x-www-form-urlencoded  
request-header: cookie =\>  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D  
request-header: referer =\> [http://myAppUrl/](http://myAppUrl/)  
request-header: accept-charset =\> ISO-8859-1,utf-8;q=0.7,_;q=0.7  
request-header: content-length =\> 101  
request-header: keep-alive =\> 300  
Read 0 bytes  
response-header: connection =\> close  
response-header: p3p =\> CP=‘OTI DSP COR NID STP UNI OTPa OUR’  
response-header: content-type =\> text/html; charset=UTF-8  
response-header: x-powered-by =\> PHP/5.1.6  
response-header: date =\> Thu, 04 Oct 2007 10:34:41 GMT  
response-header: server =\> Apache/2.2.4 (Fedora)  
response-header: content-length =\> 0  
response-header: set-cookie =\>  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D;  
expires=Sun, 01-Oct-2017 10:34:41 GMT,  
pmv\_ck\_session=YToyOntzOjU6ImxvZ2luIjtzOjM6InNlYiI7czo4OiJwYXNzd29yZCI7czozMjoiMGNhYzVlYWIxNWZlOWY2YTFlZmQzOGI3YzEwM2NkZDciO30%3D;  
expires=Thu, 04-Oct-2007 11:34:41 GMT  
response-header: location =\> myAppUrl  
saved cookie:  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D  
saved cookie:  
pmv\_ck\_session=YToyOntzOjU6ImxvZ2luIjtzOjM6InNlYiI7czo4OiJwYXNzd29yZCI7czozMjoiMGNhYzVlYWIxNWZlOWY2YTFlZmQzOGI3YzEwM2NkZDciO30%3D  
status: 302  
follow redirect to: myAppUrl  
Net::HTTP::Get: /  
using cookie:  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D  
request-header: accept-language =\> en-us,en;q0.5  
request-header: connection =\> keep-alive  
request-header: accept =\> _/_  
request-header: accept-encoding =\> gzip,identity  
request-header: user-agent =\> Mozilla/5.0 (Macintosh; U; PPC Mac OS X;  
en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3  
request-header: cookie =\>  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D  
request-header: referer =\> myAppUrl  
request-header: accept-charset =\> ISO-8859-1,utf-8;q=0.7,\*;q=0.7  
request-header: keep-alive =\> 300  
Read 519 bytes  
Read 935 bytes  
Read 1959 bytes  
Read 2375 bytes  
Read 3399 bytes  
Read 3803 bytes  
response-header: connection =\> close  
response-header: p3p =\> CP=‘OTI DSP COR NID STP UNI OTPa OUR’  
response-header: content-type =\> text/html; charset=utf-8  
response-header: x-powered-by =\> PHP/5.1.6  
response-header: date =\> Thu, 04 Oct 2007 10:34:41 GMT  
response-header: server =\> Apache/2.2.4 (Fedora)  
response-header: content-length =\> 3803  
response-header: set-cookie =\>  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D;  
expires=Sun, 01-Oct-2017 10:34:41 GMT,  
pmv\_ck\_session=YToyOntzOjU6ImxvZ2luIjtzOjk6ImFub255bW91cyI7czo4OiJwYXNzd29yZCI7YjowO30%3D;  
expires=Thu, 04-Oct-2007 11:34:41 GMT  
saved cookie:  
pmv\_ck\_view\_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D  
saved cookie:  
pmv\_ck\_session=YToyOntzOjU6ImxvZ2luIjtzOjk6ImFub255bW91cyI7czo4OiJwYXNzd29yZCI7YjowO30%3D  
status: 200

* * *

this application seems to use redirection and probably there is a  
problem with the cookies session ?

i can see a ’ pmv\_ck\_session ’ cookie and a ‘pmv\_ck\_view\_conf’ sent by  
app.  
Maybe ’ pmv\_ck\_session ’ is not use correctly ?

what’s wrong with my code ?

thanks in advance

zeb
