[英]Variables and session variables not working in php includes
好吧..原谅我,已经发布了几个类似的问题,并提供了正确的答案......我知道总有一天我会向互联网上的人寻求帮助,但我从没想过这会如此愚蠢......
这是我的代码..到目前为止..
索引.php:
include "http://www.mywebsite.com/shared.php";
$page = "homepage";
include "http://www.mywebsite.com/htmlheader.php"; //trying to use "page" variable in here
echo ("<br>test2: " . $_SESSION['test']);
include "http://www.mywebsite.com/htmlfooter.php";
共享.php:
session_start();
$_SESSION['test'] = "what the f_ck im scared";
htmlheader.php:
echo ("test1: " . $page . "<br>" . $_SESSION['test']);
现在的输出是:
测试1:
测试2:
(所以页面被包括在内..只是无法使用变量..)根据我目前的理解,这应该打印如下内容:
测试1:我害怕什么
测试2:主页我害怕什么
..有趣的是,我对使用变量的包含没有任何问题。 我添加了一些东西,但后来它随机停止工作,所以我把它缩小到这个,试图找出问题所在......我假设我犯了一些愚蠢的错误。
确保您已使用session_start();
启动会话session_start();
还要检查是否在 php.ini 中将allow_url_fopen
或allow_url_include
或两者都设置为 0(禁用)。 如果是,请尝试激活它
include "htmlheader.php";
代替
include "http://www.mywebsite.com/htmlheader.php";
确保你有session_start();
在includes
的页面顶部
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.