Saturday 15 June 2013

html - Return a value to a CGI script -



html - Return a value to a CGI script -

in main script, main.cgi, nowadays user form login. when form submitted it, script called perform verification, login.cgi.

login.cgi

# convert request method uppercase eg: get, post $env{'request_method'} =~ tr/a-z/a-z/; # if "post" request sent, check login credentials if ("$env{'request_method'}" eq "post"){ # login parameters $username = param('username'); $password = param('password'); $logincheckresult = check_login($username, $password); # if login successful, create cookie if ($logincheckresult){ # set cookie $cookie = cgi::cookie->new(-name=>'userid',-value=>$cookie_value); print redirect(-uri => '/cgi-bin/main.cgi/', -cookie => $cookie); # if login unsuccessful, redisplay login page } else { # here... } }

if login successful, create cookie , send user main page. here can test if cookie existent determine whether login successful.

however, i'm not sure if login unsuccessful.

main.cgi

if ($cookie eq ""){ print show_login_form(); # login successful } else{ print $cookie; }

if redirect them main.cgi, login form showed 1 time again no error displayed. if include error message underneath

print show_login_form();

then showed. there way send variable indicate login failed , check variable in main.cgi?

or should create login form in login.cgi upon unsuccessful login effort , include error message in form?

thank help.

the code in 'successful login' code path code generated page logged-in user should see.

html apache perl cookies cgi

No comments:

Post a Comment