$ _SESSION,PHP,iframe,未获取SESSION变量 [英] $_SESSION, PHP, iframe, not getting the SESSION variables
问题描述
我正在创建一个非常简单的基于PHP的程序来进行仓储,但后端程序却相当复杂.
I m creating a very simple PHP-based program for warehousing but quite complicated back-end process.
-
我有一个登录页面,该页面直接转到授权页面,在该页面中它首次设置
session_name
,session_start()
并设置会话变量.
授权页面之后,它转到main.php页面,该页面的左侧是菜单(链接)的表,我也做了session_name()
<-与从中创建的名称相同(1),然后开始会话.
After the authorization page, it goes to the main.php page that is a table with left hand side for menu (links) that I also did session_name()
<-- same name as the one created from (1), and start the session.
主页的右侧是当用户单击左侧的链接时显示页面的iframe.我也做了session_name()
<-与(1)中创建的名字相同的名字,然后开始会话.
On the right hand side of the main page is the iframe that display the page when user click the links on the left. I also did session_name()
<-- same name as the one created from (1), and start the session.
问题:
main.php可以,它可以完美读取会话变量,但是iframe无法获取会话变量(我尝试print_r($_SESSION)
,然后变成空).我尝试了var_dump(session_name("abc"))
,其中"abc"是我在(1)中使用的会话名称,它确实显示"abc",尝试了(isset($_SESSION)
)并返回true ...所以我不知道我在做什么错...
Problem:
main.php is ok, it reads the session variable perfectly, but the iframe couldn't get the session variables (i tried to print_r($_SESSION)
, and came up empty). I tried var_dump(session_name("abc"))
, where "abc" is the session name that i used in (1), and it does show "abc", tried (isset($_SESSION)
) and returns true... so I don't know what am I doing wrong...
对不起,我想我可能已经找到了罪魁祸首...这是我这方面的逻辑错误...当用户级别未经授权使用时,我有这种情况可以检查我创建的用于销毁会话的每个php页面当前页面.非常糟糕.非常感谢您的帮助!!
I m sorry guys, i think i may have found the culprit... it is a logic error on my side... i have this condition to check every php page i created to destroy session when the user level is not authorized to use this current page. My bad.. thanks so much for your help guys!!
推荐答案
确保session_start()
在所有页面上:
session_start()创建会话或恢复当前会话,该会话基于通过GET或POST请求传递或通过cookie传递的会话标识符.
session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.
请参见 PHP手册参考
要控制$ _SESSION的内容,请尝试在所有ifreame页面中放入代码:
To control the contents of the $_SESSION try to put in all ifreame pages the code:
<?php
session_start();
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
这篇关于$ _SESSION,PHP,iframe,未获取SESSION变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!