CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Session fails when working script is included from PHP

 



Zhris
Enthusiast

Jun 23, 2010, 8:49 PM

Post #1 of 3 (507 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:


Code
<?php include("http://domain.co.uk/url/to/script/eBook-Links.pl") ?>


And here is the Perl:


Code
#! /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)


shawnhcorey
Enthusiast


Jun 24, 2010, 5:54 AM

Post #2 of 3 (496 views)
Re: [Zhris] Session fails when working script is included from PHP [In reply to] Can't Post

When you say you run it directly, is that from the command line? When you put this location, http://domain.co.uk/url/to/script/eBook-Links.pl in your browser, does it give the correct response?

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


Zhris
Enthusiast

Jun 24, 2010, 12:56 PM

Post #3 of 3 (490 views)
Re: [shawnhcorey] Session fails when working script is included from PHP [In reply to] Can't Post

Hi,

Thank you for replying. When I say I run it directly I mean when I go to the location http://domain.co.uk/url/to/script/eBook-Links.pl.

I wasn't sure if I would recieve a response so I cross posted this question at Tek-Tips.com. Although I didn't recieve a definate solution I was some what able to make it work as I anticipated using the following (but its a very brute method):


Code
<?php 
exec("/usr/bin/perl; perl eBook-Links.pl", $output);
array_shift($output); array_shift($output); array_shift($output); array_shift($output); array_shift($output);
echo implode($output);
?>


I also noticed the Perl module PHP::Sessions which would allow me to create the session in perl and php, in my perl script, although I have never been able to install modules on my webserver.

Thanks again,

Chris

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives