Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sitewide cookie with CGI.pm?

Posted on 2003-11-19
4
Medium Priority
?
309 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

876 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