
Zhris
User
Jun 23, 2010, 8:49 PM
Post #1 of 3
(195 views)
|
|
Session fails when working script is included from PHP
|
Can't Post
|
|
Hello, I have a perl script which: 1) checks if the user is logged in 2) if they are logged in, prints the corresponding links 3) otherwise they are logged out, prints the corresponding links It works absolutely fine if I run the Perl script directly. However as soon as I run the Perl script from a PHP script using the PHP include() function, it doesn't recognize the user is logged in, as if the session code has failed. Note that both scripts are located in the same directory. Is there anybody who is able to explain to me why I am having this problem and how I could possibly solve it? The PHP contains ONLY the following line:
<?php include("http://domain.co.uk/url/to/script/eBook-Links.pl") ?> And here is the Perl:
#! /usr/bin/perl use strict; use CGI ':standard'; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; use CGI::Session qw/-ip-match/; $CGI::POST_MAX = 2000000; use HTML::Template; # use Cwd; require (getcwd().'/Library.lib'); ##### # Variables my %data; ##### # Verify logged in $data{'Session'} = VerifyLoggedIn(); sub VerifyLoggedIn { my $session = CGI::Session->load() or die CGI::Session->errstr; if (($session->is_expired) || ($session->is_empty)) { $session = new CGI::Session(); } print $session->header(); # if ($session->param(-name=>'LoggedIn')) { $session->expire('LoggedIn', "+10000s"); $session->flush(); return $session->param(-name=>'LoggedIn'); } else { return 0; } } $data{'eBookLinks'}{'Pass'} = ($data{'Session'}) ? 1 : 0; ##### # Build template my $template = HTML::Template->new(type => 'filehandle', source => *DATA); $template->param ( eBookLinksPass => $data{'eBookLinks'}{'Pass'} ); ##### # Print #print "Content-type: text/html\n\n"; print $template->output; ##### # Template data __DATA__ <TMPL_IF eBookLinksPass> <li class="inner"><a href="eBooks.pl?View=All">All eBooks</a></li> <li class="inner"><a href="eBooks.pl?View=Free">Free eBooks</a></li> <li class="inner"><a href="eBooks.pl?View=My">My eBooks</a></li> <li class="inner"><a href="Options.pl">Options</a></li> <li class="inner"><a href="Login.pl?Logout=true">Logout</a></li> <TMPL_ELSE> <li class="inner"><a href="Login.pl">Login</a></li> <li class="inner"><a href="Register.pl">Register</a></li> <li class="inner"><a href="Forgotten-Password.pl">Forgotten Password</a></li> </TMPL_IF> Thanks alot, Chris
(This post was edited by Zhris on Jun 23, 2010, 9:02 PM)
|