in reply to Persistent login session with restricted access

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^2: Persistent login session with restricted access
by BUU (Prior) on Oct 09, 2004 at 22:32 UTC
    A) Perl is spelt perl or Perl, never PERL. PERL is just plain wrong.

    B) PHP is never the right way.

    C) Embedding code in html pages is generally considered bad form, depending on what the code does. The reasons behind this is because people generally prefer to seperate content and application logic from design elements.

    Your first example of php code is a bad example of embedding logic in to your html page, you would be better served by having one central script that can check for an appropiate log in and take appropiate action.

    Your second example is probably a good example of embedding logic in your your html, in this case your logic is only controlling the presentation of the page.
Re^2: Persistent login session with restricted access
by Errto (Vicar) on Oct 10, 2004 at 01:27 UTC

    A Perl approach to this type of thing (which I believe is what the OP requested) would probably include the use of a templating system. Template (the Template Tooklit) is one good choice. In that case your first line of code would appear in the main part of the script as:

    $args->{logged_in} = some_boolean_expression;

    where $args is the hash containing the arguments for Template's process method. Then in the template you'd have

    [% IF logged_in %] some stuff here [% END %]

    If the "some stuff here" were very large, and you find enormous IF blocks distasteful (which many do), then you could instead have

    [% IF logged_in %] [% PROCESS stuff %] [% END %]

    where "stuff" is the name of another template that contains only the things that should appear if the user is logged in. This is a good solution where you have a substantial amount of content to show only for logged in users, and a substantial amount of content for either situaion.

    If, OTOH, the page you want the user to see is completely different depending on whether they're logged in or not, you don't need a condition in your template at all. In that case, simply have your script invoke a different template altogether, depending on the status.

      I am not worried about knowing what to do once I know whether or not someone is logged in.

      My problem is letting someone login if he is not already logged in, and detecting within my script whether or not someone is logged in.