简体   繁体   English

将php会话变量传递到多个页面

[英]Passing php session variables to multiple pages

I am having problems passing session variables on my website. 我在通过网站传递会话变量时遇到问题。 I can echo my session variables on the advertiser/page2.php but when i go to a 3rd page the sessions are gone. 我可以在Advertiser / page2.php上回显会话变量,但是当我转到第3页时,会话就消失了。

Can someone please help me fix this issue? 有人可以帮我解决这个问题吗?

login.php login.php

session_start();

$_SESSION['account_id']= $account_id;
$_SESSION['user_email']= $user_email;

advertiser/page2.php Advertiser / page2.php

session_start();

advertiser/page3.php Advertiser / page3.php

session_start();

here are the settings on my phpinfo() 这是我的phpinfo()上的设置

Directive   Local Value Master Value

session.auto_start  Off Off

session.bug_compat_42   Off Off

session.bug_compat_warn On  On

session.cache_expire    180 180

session.cache_limiter   nocache nocache

session.cookie_domain   no value    no value

session.cookie_httponly Off Off

session.cookie_lifetime 0   0

session.cookie_path /   /

session.cookie_secure   Off Off

session.entropy_file    no value    no value

session.entropy_length  0   0

session.gc_divisor  100 100

session.gc_maxlifetime  1440    1440

session.gc_probability  1   1

session.hash_bits_per_character 5   5

session.hash_function   0   0

session.name    PHPSESSID   PHPSESSID

session.referer_check   no value    no value

session.save_handler    files   files

session.save_path   no value    no value

session.serialize_handler   php php

session.use_cookies On  On

session.use_only_cookies    Off Off

session.use_trans_sid   0   0

I have run into this issue several times with PHP and it is frustrating, 我用PHP碰到过几次这个问题,令人沮丧,

What I do not is set the Session ID using session_id([new_session_id]) to the MD5 ( http://php.net/manual/en/function.md5.php ) hash of a string such as the username combined with some arbitrary string. 我没有使用session_id([new_session_id])将Session ID设置为MD5( http://php.net/manual/en/function.md5.php )字符串的哈希值,例如用户名和任意字符串串。 The username is always tied to the user data. 用户名始终与用户数据绑定。

The session ID is always recalculated (which might be a minimal performance cost) but you can always find the session when you need it, since the result is deterministic. 会话ID始终会重新计算(这可能是最低的性能成本),但是由于结果是确定性的,因此您始终可以在需要时找到会话。

I am not sure if this is the BEST method, but something around that idea seems to have never failed me when dealing with maintaining sessions in PHP. 我不确定这是否是BEST方法,但是在使用PHP维护会话时,围绕这个想法的事情似乎从未使我失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM