[Catalyst] Manipulating CGI cookie via Catalyst

sindharta_tanuwijaya at yahoo.co.jp sindharta_tanuwijaya at yahoo.co.jp
Wed May 28 03:25:59 BST 2008


Thank you for your response. But I am still having the same problem if I don't use Javascript.

I added:

$c->delete_session('Logout'); in Root/default
    $c->res->cookies
         ->{id} = {
             value => [],
             expires => time()-86400,
         };
    $c->res->cookies
          ->{session} = {
              value => [],
              expires => time()-86400,
          };
 
and the Firebug Net log would generate:
----------------------------------
Response Headers
Connection  close
Date  Wed, 28 May 2008 02:13:04 GMT
Content-Length  3345
Content-Type  text/html; charset=utf-8
Set-Cookie  catalyst_session=cb50670fae865f6266b0bb2c5b992c88093b8dbe; domain=.shindaru.my.office.com; path=/; expires=Wed, 28-May-2008 02:13:04 GMT session=; path=/; expires=Tue, 27-May-2008 02:13:04 GMT id=; path=/; expires=Tue, 27-May-2008 02:13:04 GMT
Status  200
X-Catalyst  5.7013

Request Headers
Host  shindaru.my.office.com:3000
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
Accept  text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  300
Connection  keep-alive
Cookie  __utma=175737056.1376894921.1211863250.1211880303.1211937459.4; session=4alqcz3qqey2wkiokonx; id=sindharta; __utmz=175737056.1211863250.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utma=175737056.1376894921.1211863250.1211880303.1211937459.4
Cache-Control max-age=0
----------------------------------

But the strange thing is, if I changed the expires into
             expires => time()+5,
the Firebug log would become:

-----------------------------------
Response Headers
Connection  close
Date  Wed, 28 May 2008 02:18:57 GMT
Content-Length  3345
Content-Type  text/html; charset=utf-8
Set-Cookie  catalyst_session=70ca66db5210730bc63ccb2fdac240543da0f1a0; domain=.shindaru.my.office.com; path=/; expires=Wed, 28-May-2008 02:18:57 GMT session=; path=/; expires=Wed, 28-May-2008 02:19:02 GMT id=; path=/; expires=Wed, 28-May-2008 02:19:02 GMT
Status  200
X-Catalyst  5.7013

Request Headers
Host  shindaru.my.office.com:3000
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
Accept  text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  300
Connection  keep-alive
Cookie  __utma=175737056.1376894921.1211863250.1211880303.1211937459.4; __utmz=175737056.1211863250.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utma=175737056.1376894921.1211863250.1211880303.1211937459.4; id=sindharta; session=4alqcz3qqey2wkiokonx; session=; id=
Cache-Control max-age=0
-----------------------------------
 
There are two 'session' and 'id' cookies in Request headers. By the way, "session" is the session set by the PHP program and the cookie_name for catalyst is "catalyst_session". 
FYI, the php program is on port 80, while the catalyst app is on port 3000, but that is not a problem, isn't it ?

Sindharta

Gabriel Vieira <gabriel.vieira at gmail.com> wrote: You need to understand how Cookies are writed.
Thery are HTTP Headers, so you may be giving an outdated value and
next the system gives a update value. Javascript writes the Cookies
after HTTP process, so the system values are irrelevant to it.

Try to use the Catalyst structure to manipulate them instead of trying
to make some code.


On Tue, May 27, 2008 at 11:07 AM, Mitch Jackson 
 wrote:
>>     delete @{ $c->session }{qw/__user/};
>>     delete @{ $c->session }{qw/id/};
>>     delete @{ $c->session }{qw/session/};
>
> Catalyst::Plugin::Session provides a "delete_session" method
> http://search.cpan.org/search?query=catalyst%3A%3Aplugin%3A%3Asession
>
>>     $c->res->cookies
>>         ->{id} = {
>>             value => [],
>>             expires => 0,
>>         };
>> But the cookies just keep appearing, no matter how many times I refresh my
>> browser.  I think there is something wrong, but I just couldn't figure out
>> where.
>
> To ask a browser to forget a cookie, the expiry date must be specified
> in the past.  Try setting expires to time()-86400.
>
> If you continue to have problems, use Firebug
> (http://addons.mozilla.org/firefox/addon/1843)  to view the http
> headers and see the actual cookie headers received by the browser and
> post those here as they are received by the browser.
>
> Kind Regards,
>
> /Mitchell K. Jackson
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



-- 
Gabriel Vieira

_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


 

 
---------------------------------
GANBARE! NIPPON! Win your ticket to Olympic Games 2008.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080528/bcc64890/attachment.htm


More information about the Catalyst mailing list