in reply to Re: Re: Re: Re: Re: Cookie not getting stores
in thread Cookie not getting stores

Where in that example you provided would you print the login form to set the possible cookies? I see you are doing pretty much two things: 1) printing the administrative page and 2) setting the cookie. But the cookie has to come from a form somewhere.

I would really like to thank you for making the rest of my programing days more than a million times easier to manage and debug. I looked over your code countless times and have taken to heart how you layout your script.

For example, I always wrote things like:

if ($pass eq $admin pass) { if (defineded $this) { }
Which got really confusing having the trailing { on the end of the line. This made it so much more difficult to find which brackets went with which and caused so many 'missing right curly bracket' warnings in the past.

Your method, which I'm using from now on:

if ($pass eq $adminpass) { #print do everything here if (defined this) { #other things would go here } #nice closing bracket, you can see where they line up } #still matches the first bracket since it doesn't get attached t +o the end of the line
If nothing else, thank you for displaying that code. It really is much better than what I've been doing and will save loads of time in each script that I write.


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Cookie not getting stores
by chromatic (Archbishop) on Dec 26, 2003 at 22:07 UTC

    I'd write out the logic in pseudocode (or function names) beforehand, just to make it easier to figure out the logical flow:

    display_login_form() unless logged_in(); display_admin_view() if is_admin(); display_normal_view(); sub logged_in { # check for a cookie # check for a 'pass' parameter if there's no cookie # create a cookie if there's a 'pass' parameter but no # cookie already # return true if either one is valid } sub display_login_form { # print a form that asks for the 'pass' parameter # exit; } sub is_admin { # check if the given password matches the admin password } sub display_admin_view { # show the administrative view } sub display_normal_view { # show the normal view }

    I switched to curly braces on the new line after working with Ovid. They take up a bit more space on the screen, but that's a good impetus to keep my subroutines short.