Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How do I use HTTP Cookies?

by Spidy (Chaplain)
on Aug 30, 2004 at 03:58 UTC ( [id://386839]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I use HTTP Cookies?
in thread How do I use HTTP Cookies?

Your version seems to make the most sense to me so far...

I need a few things explained though. These are the lines:
my $user = $justloggedin;

my $newcookie = $query->cookie( -name => 'arbitrarycookiename', -value => $user, -expires => '+15m'); #no activity in 15min...gone! my $user = $query->cookie('arbitrarycookiename'); #read it if ($user) { $stillloggedin } else { &loggin() }

Otherwise, I'm pretty sure I understand most of it...what are $query and $stillloggedin doing? (&loggin() is trying to log in if it didn't work, right?)

Replies are listed 'Best First'.
Re^3: How do I use HTTP Cookies?
by csuhockey3 (Curate) on Aug 30, 2004 at 04:35 UTC
    'I need a few things explained though. These are the lines'

    Those are all of the 'lines' that deal with the cookie. So all I got from your reply is that you know how to decalare variables and write a print statement? As far as your question about query:

    $query: This will parse the input (from both POST and GET methods) and store it into a perl5 object called $query.

    As read in the POD. I think $stilllogged should be pretty intuitive. Have you looked at any of the documentation of CGI or CGI::Cookie yet (as we asked in the beginning)? I am not being condescending, but it sounds like that is where you need to start. It is critical you can understand what you are using or trying to use so we can help you. The documentation usually can answer many of your questions quite quickly.
      I read the documentation, and it's not making too much sense to me...I think I'll try reading it again.
Re^3: How do I use HTTP Cookies?
by bradcathey (Prior) on Aug 30, 2004 at 12:41 UTC

    Expanded, that 1st line is showing that you are receiving the user's name as input from an HTML form. So...

    my $user = $query->param('username');

    You can keep this in a hidden field in the form.

    $query

    is an arbitrary, but oftused name for the CGI session variable. Read all about it in the CGI docs.

    $stillloggedin

    ...simply represents what redirection you would use if the user is found in the cookie, indicating their cookie has not timed out and that they are still logged in. Otherwise (&loggin), take them to an HTML form where they have to re-log-in.

    Update: Check out Ovid's CGI course, as well the CGI Tutorials here in the Monastery. Super Searching will find enough on the topic to choke a horse. Also, bear in mind, what I have presented is a very simple solution. It is not secure (though the username is less important this way than the password—another huge topic among monks). There are more complicated scenarios using a database, in combination with cookies, to track who's logged in, etc. Cookies are not always enabled, so database methods might be invoked, and beyond the scope of this thread. (Update 2: fixed typos in my first Update—where's Preview when you need it :^)


    —Brad
    "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://386839]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-24 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found