如何访问其他文件中的会话变量 [英] How to access session variable in other file

查看:70
本文介绍了如何访问其他文件中的会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

# Object initialization:
use CGI::Session;

$session = CGI::Session->new();

$CGISESSID = $session->id();

# Send proper HTTP header with cookies:

print $session->header();

# Storing data in the session:

$session->param('User_id', 'U00002');

这个脚本是写在某个文件中的,比如 abc.pl.

This script is written in some file say abc.pl.

现在我想访问其他 perl 文件中的 User_id,比如 xyz.pl.怎么做?我需要对这个脚本做任何改变吗?

Now I want access the User_id in some other perl file, say xyz.pl. How to do that? Do I need to make any change in this script?

推荐答案

use CGI::Session qw();
my $s = CGI::Session->new;
$s->param(User_id => 'U00002');
my $id = $s->id; # e.g. '4cd29ac608405e4d0a463d153e64defd'

将 id 传递到需要的地方.

Pass the id to where it's needed.

use CGI::Session qw();
my $s = CGI::Session->new($id);
print $s->param('User_id'); # 'U00002'

这篇关于如何访问其他文件中的会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆