Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Passing flags between invocations of a cgi script

by Herbert37 (Novice)
on May 17, 2010 at 18:38 UTC ( [id://840396]=perlquestion: print w/replies, xml ) Need Help??

Herbert37 has asked for the wisdom of the Perl Monks concerning the following question:

I am unable to figure out a way to pass a flag between two invocations of the same cgi script (form) (i.e. a script with a blank "action"). If, for example, I set a scalar variable $foo based on the value of a parameter in the form, that variable is clobbered by its "my" declaration the next time through the form. I know that I am missing something trivial, but I can't figure it out. Thanking you...

Replies are listed 'Best First'.
Re: Passing flags between invocations of a cgi script
by SuicideJunkie (Vicar) on May 17, 2010 at 18:57 UTC

    If they are separate invocations, why would you expect the variables to jump from one thread or process to another?

    It seems to me that you want the first invocation to return a page containing a modified version of the form: entry fields containing a default value equal to what the user sent the first time, or perhaps a hidden field containing a session ID so that the second invocation can pull the desired historical values from disk.

      It is a single user invoking the form, selecting an answer, and, then, depending on whether it is the "right" answer, either getting the same version of the form with his/her answer left intact and an admonition to respond again, or being told s/he answered correctly and being given a "new" question. I load the question and the possible answers from a database. In the "wrong" answer case, I want to leave the database alone. In the "right" answer case, I want to visit it again and get a new question. Thank you for considering this question, which clearly contains a moderate share of ignorance.

        The thing to keep in mind is that your script is started, deals with a request and then terminates. Nothing should survive except what you have written to disk, and what the user knows.

        But you can't trust the user, so don't believe anything they say or the sister of bobby tables will tell you that her name is "admin", authenticated=1 and/or score=1000000 ;)

        Instead of real info, only give them a session ID that is really hard to guess (say, 32 random hex characters), and delete session info that is older than 30 minutes. Use the string they reply with to find and load the user's session info (last question/score/login name/etc). If it doesn't exist, send them to the login screen.

        Edit: Fixed link

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-29 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found