Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Fellow Monasterians,

I have a CMS that users must log into. Besides the login, there are several modules, used for various tasks, that check for the existence of the login when they are invoked.

Some users are reporting being forced to log in twice, once at the first login screen, and a second time after a requested module is invoked.

After hours of testing I finally realized that if a user does not use www. in the URI, the browser was ignoring the 1st cookie set at login, and necessitating a 2nd cookie to proceed.

So, the user enters: domainname.com/admin, but after failing, the browser fills in the address with the full URI as http://www.domainname.com and all is fine. The cookies are showing:

WebsiteValue
First login attempt:
domainname.comCGISESSID
Second login attempt:
www.domainname.comCGISESSID

The code to create the cookie was:

use CGI::Session; my $session = new CGI::Session(); my $cookie = $query->cookie( CGISESSID => $session->id, ); print $query->header(-cookie => $cookie);

So I thought I'd add the domain to the cookie params:

(my $http_host = $ENV{'HTTP_HOST'}) =~ s/(www.)?([\w\-.]+)/$2/; my $cookie = $query->cookie( CGISESSID => $session->id, -domain => ".".$http_host, ); print $query->header(-cookie => $cookie);

Still no dice. The docs for CGI::Cookie say that the dot form of the domain param, e.g., -domain => .domainname should work for any form of the domain name.

QUESTION: how do I set a proper cookie, irregardless of what the user enters as a starting URI?

Resolved: I set the <base href /> tag in the login tmpl file via $template->param(basehref => $http_post);. The cookie wrote correctly and all is well.

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to Unable to set cookies for specific domain by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-19 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found