【问题标题】:create session in Perl and read session variables in PHP在 Perl 中创建会话并在 PHP 中读取会话变量
【发布时间】:2015-04-28 12:03:08
【问题描述】:

我有一个 Perl 脚本,它尝试向 PHP 服务器发出 post 请求。 使用 LWP::UserAgent 进行发布请求,使用 CGI::Session 处理会话。

现在,帖子上没有大问题,但是在 Perl 中设置会话变量:用户名后,我无法从 $_SESSION['username'] 获取值。尝试使用 PHP::Session,也没有运气。

Perl:

use strict;
use warnings;

use CGI;
use CGI::Session;
use LWP::UserAgent;

my $cgi = CGI->new();
my $session = CGI::Session->new( 'serializer:php' );
$session->param('username', 'dev');
print "::Perl session id::" . $session->id() . "::\n";

my $browser = LWP::UserAgent->new;
my $url = 'http://localhost/test.php';
my $response = $browser->post( $url,
  [ 
    'date' => '2015-02-25'
  ]
);

die "$url error: ", $response->status_line
 unless $response->is_success;

my $file_data = $response->content();
print $file_data;

PHP:

<?php
session_start();
echo "::PHP session id::" . session_id() . "::\n";
echo "::" . $_POST['date'] . "::\n";
echo "::" . $_SESSION['username'] . "::\n";    
?>

通过执行 Perl 脚本,我得到了输出:

::Perl session id::737ba07ad1a2ced0be07cd303cf08afe::
::PHP session id::ri60ivtb32lglcrqv4ug1sb2i5::
::2015-02-25::
::::

$_SESSION['username'] 未正确检索。并且会话 id 不同。

【问题讨论】:

  • 在 perl PHPSESSID 中设置一个 cookie,其中包含 perl sessioin id
  • 这两个应用程序在同一台服务器上吗?
  • perl 脚本位于 C:\wamp\ 下,会话文件在 C:\wamp\tmp 下创建
  • @feng63600 我想你误解了它的工作原理。为什么需要 perl 脚本中的会话 id 值等于 PHP session_id?两个脚本中的每个会话 ID 都是单独创建的。
  • @KostiaShiian 我明白了。为什么在 Perl 中设置的会话变量无法在 PHP 中检索?

标签: php perl session


【解决方案1】:

我没有找到一个理想的 Perl 模块来处理 Windows 上的 SFTP/FTP。 相反,使用 Win32::OLE->new('WinSCP.Session') 获得一些运气。

用法:http://winscp.net/eng/docs/library_perl

【讨论】:

    猜你喜欢
    • 2015-12-18
    • 2011-03-08
    • 1970-01-01
    • 2013-08-03
    • 2010-09-25
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多