Solved

Sitewide cookie with CGI.pm?

Posted on 2003-11-19
4
291 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now