here you are,
also are running apache server with perl
#!c:/perl/bin/perl.exe -w $cfh = select (STDOUT); $| = 1; select ($cfh); #the above line is to provide the scripts interpreter location-------- +>scripts: login.pl #---------------------------------------session_start.pl #---------------------------------------#include the libraries: use CGI qw/:standard/; # load standard CGI routines use CGI; #load the object orentird CGI use DBI; # load DBI library use CGI::Session; # load the Session library use CGI::Carp qw(fatalsToBrowser); # load CGI-Carp for browser er +rors handling my $query = new CGI; #---------------------------------------# if( $query->param("Submit") ){ our $message; #-------check the login if ($query->param("login")) { $login1 = $query->param("login"); unless ($login1 =~ /^[a-z0-9_]+$/) { $login = ''; $message .= 'The login ID contains invalid character!<br>'; }else{ $login = $query->param("login") } }else{ my $login = ''; $message .= 'You forget to enter your login ID!<br>'; } #-------check the password if ($query->param("password")) { $password1 = $query->param("password"); unless ($password1 =~ /^[a-z0-9_]+$/) { $password = ''; $message .= 'The password contains invalid character!<br>'; }else{ $password = $query->param("password") } }else{ my $password = ''; $message .= 'You forget to enter your password!<br>'; } if ($login && $password) { #---------------------- my $sqlstatement="bla bla"; my $sth = $dbh->prepare($sqlstatement); $sth->execute || die "Could not execute SQL statement ... maybe invali +d? $DBI::errstr"; my @row=$sth->fetchrow_array; if (@row) { our $first_name = $row[0]; our $last_name = $row[1]; our $user_id = $row[2]; our $admin = $row[3]; our $user_address = $row[4]; #----------create the user session my $session = new CGI::Session("driver:File", $query, {'Directory' => +"C:\\session\\"} ) or die "S!"; $session->header(); my $session_id = $session->id(); #get the session I +D $session->param('username', $username); #add the username +to the session $session->param('user_id', $user_id); #add the user_id t +o the session $session->param('first_name', $first_name); #add the first_nam +e to the session $session->param('last_name', $last_name); #add the last_name + to the session $session->param('address', $user_address); #add the address t +o the session $session->param('admin', $admin); #add the admin ide +ntity to the session #save session params in the $query object $session->expire('+10m'); #session should e +xpire after 10 minutes $cookie = $query->cookie(CGISESSID => $session->id); print $query->header( -cookie=>$cookie ); print $query->header(-type => 'text/html', -cookie=>$cookie, -location +=>'http://localhost/cgi-bin/cars/loggedin.pl' ); exit; #-------------- finish MySQL statement $sth->finish(); #-------------- disconnect from database $dbh->disconnect(); }else{ $message .= 'The username and the password do not match <br>t +hose in the record.<br>'; } }else{ $message .= 'Try again.'; } } #---------the param bracket

In reply to Re^4: Cookie, redirect by Anonymous Monk
in thread Cookie, redirect by wolf25

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.