Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Sitewide cookie with CGI.pm?

Posted on 2003-11-19
4
303 Views
Last Modified: 2013-12-25
Been programming perl and doing web programming for years and years but never really mucked with cookies too much.

I have the following code:
$session->param(-domain =>      ".".$self->{domain});
$session->param("username", $username);
$session->param("userId", $userId);
$session->param("perms", $perms);
$session->expires(_IS_LOGGED_IN => '+2h');
my $cookie = $q->cookie($self->{sessionName} => $session->id);

(the $session object is from CGI::Session)

This sets a cookie for www.mydomain.com, stuff.mydomain.com, things.mydomain.com, etc.  But it doesn't set the cookie for simply mydomain.com.  I prefer to access the domain by just using mydomain.com.  But it won't recognize the cookie that way.  
The CGI.pm documentation states:
Domain names must contain at least two periods to prevent attempts to match on top level domains like ".edu".

So I couldn't set a cookie with -domain => "mydomain.com" to cover all urls under and including mydomain.com.  

How would I work around this?

Thanks for any help!
0
Comment
Question by:dbunder
  • 3
4 Comments
 

Accepted Solution

by:
Teh_Craze earned 50 total points
ID: 9939722
Why not just use CGI::Session and CGI::Cookie ?

If you use these two modules, it's secure enough, generates a unique session ID, that's stored on server, and in a cookie, then stores data in that session-id file on the server. So nothing is actually on the client side, except the cookie.

If you would like some more info on this method, please just ask, and I will post a script.
0
 
LVL 1

Author Comment

by:dbunder
ID: 9940442
Hmmmm I can't believe I never even thought to use CGI::Cookie.  I'll take a look at it tonight and let you know how it works out.
0
 
LVL 1

Author Comment

by:dbunder
ID: 9951084
It doesn't seem to work.  Simply, I'm doing this:

$cookie = new CGI::Cookie(-name=>param1 -value=>param2);
print header(-cookie=>$cookie);

to retrieve the cookie...
%cookies = fetch CGI::Cookie;
my val = $cookies{'cookieName'}->value

If I log in at http://example.com and then go to http://example.com/membersarea, I'm fine.  If I log in at http://example.com and go to http://www.example.com it doesn't see the cookie and kicks me back to the login page.  I checked my cookies after logging in with a cookie browser and the cookie is set at ".example.com" after I login at http://example.com.

Any other ideas?  I'd like users to be able to use whatever url they'd like.
0
 
LVL 1

Author Comment

by:dbunder
ID: 9951158
Nevermind.  I had to explicitly set the domain even though the CGI::Cookie docs say it'll choose the best value for the domain it wasn't working.  Working wonderfully now.  Thanks!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question