Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: cookie problem (cgi101)

by Anonymous Monk
on Nov 12, 2014 at 03:25 UTC ( #1106934=note: print w/replies, xml ) Need Help??


in reply to cookie problem

This is how you write that stuff ( both home.pl and wel.pl ), you print from Main, your ThisPage() or ThatPage() returns $headers, $body

#!/usr/bin/perlml -- ## ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while " -otr + -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use CGI (); use CGI::Carp qw( fatalsToBrowser ); Main( @ARGV ); exit( 0 ); sub Main { my $q = CGI->new; return print GoToWellWithCookies( $q ); } ## end sub Main sub UrlFor { my( $q, $path ) = @_; return $path; } ## end sub UrlFor sub ValidLogin { my( $q ) = @_; my $user = $q->param( 'login' ); my $pass = $q->param( 'pass' ); ## YOUR JOB :) return !!1 if $user eq $pass; return !!0; } ## end sub ValidLogin ## sub TryAndLoginToGoHome ## accepts $query ## returns $headers, $body; ## sub GoToWellWithCookies { my( $q ) = @_; if( my $user = ValidLogin( $q ) ) { my $cookie = $q->cookie( -name => 'id', -value => $user, -expires => '+2m', -path => '/', ); return $cg->redirect( -location => UrlFor( $q, "wel.pl" ), -cookie => $cookie, ); } else { ; return $cg->redirect( -location => UrlFor( $q, "home.pl" ), ); } } ## end sub GoToWellWithCookies __END__ __END__

Replies are listed 'Best First'.
Re^2: cookie problem (cgi101)
by Anonymous Monk on Nov 12, 2014 at 16:03 UTC
    i have understand your post bt wat am confused of wat to use in home.pl and wel.pl i see it as one scrip for 1 page

      i have understand your post bt wat am confused of wat to use in home.pl and wel.pl i see it as one scrip for 1 page

      Its an example of how you should write your programs so that cookies work for you (Main prints, ThisPage or ThatPage return $headers, $body, which Main prints)

      Its an example based on code you posted for home.pl

      You should fix it up and write the same way for wel.pl

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-05-28 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (99 votes). Check out past polls.

    Notices?