This HOWTO teaches you how to share a cookie within multiple domains. Let's say www.example.com and shop.example.com for example, If people logged in www.example.com. And you don't want people to do login again in shop.example.com and keep the state, Then, you need this howto.

It's pretty simple, You just need to add the cookie_domain for session BEFORE calling the session accessor.

sub auto : Private {
    my ($self$c) = @_;
    $c->config->{session}->{cookie_domain} = '.example.com';

# Test code below
    my $count = ($c->session->{count} += 1);
    $c->res->body("Count is $count");
}

But here is one IMPORTANT note for doing test on localhost. The domain names you test must look like the "real" domain names. For example, You want to add aliases for your host(through /etc/hosts file). The aliased domain names must contain at least 2 dots, If you only change your testing domain to something like, www.localhost or shop.localhost for your localhost, It won't work at all. you MUST change it to something like www.localhost.com or shop.localhost.com.

My tags:
 
Popular tags:
 
Powered by Catalyst
Powered by MojoMojo Hosted by Shadowcat - Managed by Nordaaker