0

I have this problem where my session cant load after the first page. It does fetch the first page session after it has been created. Here is my first page :

index.cgi

use strict;
use warnings;
use CGI qw/:standard/;                  
use CGI::Session qw/-ip-match/;              
use CGI;                
use DBI;                
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);

my $username;
my $password;
my $session;
my $sid;
my $cookie;

my $cgi = CGI->new();
my $submit = CGI->new();
my $a = CGI->new();

$username = $a->param('username');
$password = $a->param('password');

$session = new CGI::Session("driver:File", undef, {Directory=>'/tmp/session'});
$sid = $session->id();
$cookie = $cgi->cookie(CGISESSID => $session->id);
$session->param("username", $username);
$session->flush();
print $cgi->header( -cookie=>$cookie,-location=>'index2.cgi' );

The first page works fine and it creates the cookies inside the directory it supposed to. It also stores the username that i wanted. Here is the results of the first page.

$D = {'_SESSION_ID' => '4244435418205139ea02fde065811aa1','_SESSION_ATIME' => 1401441306,'_SESSION_REMOTE_ADDR' => '127.0.0.1','username' => 'admin1','_SESSION_CTIME' => 1401441306};;$D

After that, the second page should load the cookie and print them in that page. But it does not work. Here is my second page :

UPDATED

index2.cgi

use strict;
use warnings;
use CGI;
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use CGI::Session qw/-ip-match/;

my $sid;
my $cookie;
my $session;
my $q;
my $name;
my $username;

my $cgi = CGI->new();

$sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef;
$session = load CGI::Session(undef, $sid, {Directory=>'/tmp/session'});

$username = $session->param("username");

print $sid;
print $session->header();

Both print in this second page returns nothing. Which means it does not load from the first page. How can i achieve this? is anything wrong with my codes? Because i studied it from CGI::Session::Tutorial. Can anybody help me?

user3463422
  • 137
  • 1
  • 1
  • 8
  • As an example, you can take a look at this answer from march: [`How to access variable of other perl program in my perl program`](http://stackoverflow.com/a/22599385/1733163) – Miller Jun 13 '14 at 00:58

1 Answers1

1

Well, for starters the Directory is different between your two pages ("/tmp/session" vs "/tmp").

AKHolland
  • 4,435
  • 23
  • 35