Hello Monks, I'm new to perl and to this community as well. I'm creating a login system with perl but getting problem abour session, i'm unable to get session data to another page. here my code, login.pl
#!/usr/bin/perl print "Content-type: text/html\n\n"; require 'learn/db_connect.pl'; use CGI; use CGI::Session qw(); use DBI; use warnings; use Digest::SHA qw(hmac_sha512_hex); $q = new CGI; my $cgi = new CGI; if($q->request_method eq "POST"){ my $uname = $q->param('uname'); my $pass = $q->param('pass'); if(defined($uname) && $uname ne ""){ if(defined($pass) && $pass ne ""){ my $pass_hash = hmac_sha512_hex($pass); my $dbh = connectDB(); my $sth = $dbh->prepare("SELECT count(id) as counted FROM +perl_users WHERE `username` = ? AND `password` = ?"); $sth->execute($uname, $pass_hash); my $ref = $sth->fetchrow_hashref(); if($ref->{'counted'} == 1){ my $sql001 = $dbh->prepare("SELECT * FROM perl_users W +HERE `username` = ? AND `password` = ?"); $sql001->execute($uname, $pass_hash); my $result = $sql001->fetchrow_hashref(); $user_id = $result->{'id'}; $username = $result->{'username'}; my $s = CGI::Session->new; $s->param("user_id" => $user_id); my $id = $s->id; print "<script>window.location.href = 'profile.pl?toke +n=".$id."';</script>"; }else{ print "<script>window.location.href = 'index.pl?error= +Invalid Username OR Password.';</script>"; } }else{ print "<script>window.location.href = 'index.pl?error=plea +se fill all fields';</script>"; } }else{ print "<script>window.location.href = 'index.pl?error=please f +ill all fields';</script>"; } }else{ print "<script>window.location.href = 'index.pl';</script>"; }
profile.pl (where i need session data)
#!/usr/bin/perl print "Content-type: text/html\n\n"; use CGI; use CGI::Session qw(); use DBI; use warnings; $get = new CGI; $token = $get->param('token'); my $s = CGI::Session->new($token); print $s->param("user_id");
Whats wrong i'm doing here ? I have tried lots of things with CGI:Session and still no luck, i'm stuck with this since last two days and feeling dumb now as i'm not new to programming. Any gelp will be highly appreciated. Thanks.

In reply to CGI Session Not Working by ninjazin

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.