You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by James G Smith <JG...@JameSmith.Com> on 2000/04/05 04:40:37 UTC

Re: advice/techniques: script control over page transitions

B&T <80...@sympatico.ca> wrote:
>I've generally created a cgi script per page.  Is that a mistake?
>(I embed the perl in my html so I can edit pages with an html editor)
>
>I need a better technique for invoking traversals to other pages.
>Right now all I can do is a redirect (internal or external).
>How do you organize things so that from within a script you can either
>display the associated page or invoke any other page/script instead?
>
>    - just do redirects?
>    - put all page generation in subroutines in one big .pm?
>    - something else (I hope)?
>
>
>Example:  My main "home" page has links to "login" and "register"
>scripts/pages, both of which eventually lead to a "user" page.
>With no parameters the login script displays an empty login form.
>Called with get/post parameters it processes the form data;
>on failure it redisplays the login form with a warning,
>on success it should take you to the "user" page (my problem).
>How would YOU organize this?
>
>There are lots of tutorials on the net, but I haven't seen anything
>about organization between multiple pages. 

The way I go about it is as follows (using a PHP page I'm working on
right now as an example -- PHP because that's what the vendor provides, 
but the principles are the same).

  1. Login page requires no information (login via one-time 
      username/password)

  2. Terms of service require login

  3. Editing default information and providing initial password
      requires valid login and agreement to terms of service

  4. Requesting confirmation requires valid login, agreement to
      the terms of service, a valid username, and valid password
      (both fields non-blank and equivalent).
 
  5. Final action requires valid login, agreement to the terms of 
      service, a valid username, valid password, and confirmation.

Since all these pages flow in a somewhat linear fashion, it is easy
to put them all in one script, or have static files which I can
include (e.g., the terms of service).  When the script is run, it
automatically selects the largest number in the sequence for which
it has valid information.  This is so someone can't jump into the
middle of the sequence without satisfying the prior requirements.
(State is determined without regard to prior states.)

This may not work for larger applications, but for bits and pieces,
it can -- I do a similar thing with Fresh::User and some of the
other Fresh::.* modules (not yet on CPAN).
------------------------------------+-----------------------------------------
James Smith - jgsmith@jamesmith.com | http://www.jamesmith.com/
            jsmith@sourcegarden.org | http://sourcegarden.org/
              jgsmith@tamu.edu      | http://cis.tamu.edu/systems/opensystems/
------------------------------------+------------------------------------------