Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Sessions problems

by f00li5h (Chaplain)
on Dec 13, 2006 at 11:00 UTC ( [id://589546]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Sessions problems
in thread Sessions problems

I presume you only seting $q when it's a POST request to make sure that users only login with POST, but i think you'll still want to have a my $q = CGI->new() since you may want to, say, set $q->cookie or do a $q->header 'location: http://elsewhere.com/' etc regardless of wether the user has posted the form...

CGI::param 'foo' will give you back foo from get/post-age, and will play nice and give you an undef if the form wasn't posted or that field wasn't supplied.

If you're not unconditionally putting something in $q then you can't trust $q to be defined and so you should check that there's something there, every time you want to call something on it. It's only safe to do $q->somestuff() if ref $q ie you can only use methods on $q if it is an object (ie if it's a blessed reference) HTH

@_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Replies are listed 'Best First'.
Re^4: Sessions problems
by Anonymous Monk on Dec 13, 2006 at 11:18 UTC
    I actually have one more question with regards to retrieving the value in the cookie from a different cgi file. I am using the sample code form the CPAN tutorial
    $name = $session->param($username); printf "<input type=\"text\" name=\$username\" value=\"%s\" />", $name +;
    Just wondering should as in the creating the session, $name here be defined as my $name ->new CGI() or just my $name also the value that i passed into the session was
    $name = $query->param($username); $session->param($username, $name);
    so in retrieving the cookie am i right to put $username into the "param" field in the line $name = $session->param($username); and into the name field in the line
    printf "<input type=\"text\" name=\$username\" value=\"%s\" />", $name +;
    Thanks again

      I'm not sure if you've read it, but Ovid wrote a CGI course that you may be interested in

      Also, merlyn wrote some neat Web Techniques Columns that may interest you.

      Oh, and I think there's a book on Perl CGI too... ;)

      @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;
Re^4: Sessions problems
by Anonymous Monk on Dec 13, 2006 at 11:06 UTC
    Adding a  my $q = CGI->new() seemed to do the trick, thanks for all the help, appreciate it!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-20 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found