Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Cookies

by Anonymous Monk
on Dec 24, 2003 at 10:08 UTC ( [id://316817]=note: print w/replies, xml ) Need Help??


in reply to Re: Cookies
in thread Cookies, how can you set one if it must be done before the header?

Thank you for your help, I've used your code and got pretty far with it, I believe, but I've run into a problem or two. I don't know if the cookie is getting set or not, but it says I'm logged in if I type in the correct password.

I have url_params that run off this script, but when I'm supposively logged in and I go to a url_param, it errors out saying I have the wrong password. Can you see a problem below with the cookie being sent? And if I reload the page after I log in, I stay logged in. But if I go back to the url using the location bar, it tells me to relog back in.

Thank you!

my $adminpassword = "test"; my %cookie; if ( !exists $cookie{'pass'} ) { if ( param() ) { my $adminpass = param('admin'); if ( $adminpass eq $adminpassword ) { my $cookiename = cookie( -name => 'cookie', -value => 'loggedin', -expires => '+1h' ); print header, start_html(); # print rest of page here print "you are logged in"; } } else { print header, start_html(); print "Incorrect password, please click back and try again +"; exit; } } else { print header, start_html(); print start_form(), table( Tr( td("Admin Password: "), td( textfield( -name => 'admin', -size => 10 ) ) ), Tr( td(), td(submit) ), ), end_form(), hr(); } }

Replies are listed 'Best First'.
Re: Re: Re: Cookies
by inman (Curate) on Dec 24, 2003 at 10:44 UTC
    I have found that Mozilla is very useful for tracking the setting and sending of cookies. All you need to do is turn on the 'Ask me before setting cookies' option in the privacy settings and you get an informational dialog each time that a cookie is set. You can then use the cookie manager to inspect the cookies that have been set.

    You may also want to dump the HTTP headers that your app received as HTML comments while you are building and debugging your app. Using Data::Dumper on your cgi object(or other objects) is also useful.

Re: Re: Re: Cookies
by edoc (Chaplain) on Dec 24, 2003 at 12:22 UTC

    IE requires the path be set in your cookie..

    my $cookiename = cookie( -name => 'cookie', -value => 'loggedin', -expires => '+1h' -path => '/', );

    cheers,

    J

      I added the path but it still doesn't change the fact that I can log in, but if I go back to the url 2 seconds afterwards it forces me to log in again.
        my $cookiename = cookie( -name => 'cookie', -value => 'loggedin', -expires => '+1h' ); print header, start_html();

        You haven't actually set the cookie just by doing that. You've created a cookie but then not sent it to the browser. You need to print the header and explicitly tell it to include the cookie.



        ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-26 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found