简体   繁体   English

在 php 中不起作用的变量和会话变量包括

[英]Variables and session variables not working in php includes

OK.. forgive me, there are a couple similar questions posted already with the correct responses... I knew someday I would have to ask the people of the internet for help but I never thought it would be something so stupid...好吧..原谅我,已经发布了几个类似的问题,并提供了正确的答案......我知道总有一天我会向互联网上的人寻求帮助,但我从没想过这会如此愚蠢......

here is my code.. so far..这是我的代码..到目前为止..

index.php:索引.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";

shared.php:共享.php:

session_start();
$_SESSION['test'] = "what the f_ck im scared";

htmlheader.php: htmlheader.php:

echo ("test1: " . $page . "<br>" . $_SESSION['test']);

Output right now is:现在的输出是:

test1:测试1:

test2:测试2:

(so the pages are being included.. just not able to use the variables..) From what I understand in its current state this should be printing something like: (所以页面被包括在内..只是无法使用变量..)根据我目前的理解,这应该打印如下内容:

test1: what the f_ck im scared测试1:我害怕什么

test2: homepagewhat the f_ck im scared测试2:主页我害怕什么

..The funny thing is I was not having any issue with the include using the variable. ..有趣的是,我对使用变量的包含没有任何问题。 I had added some things but then it randomly stopped working so I reduced it down to this to try and figure out what the problem was.. I am assuming I have made some silly mistake.我添加了一些东西,但后来它随机停止工作,所以我把它缩小到这个,试图找出问题所在......我假设我犯了一些愚蠢的错误。

Ensure that you have started the session with session_start();确保您已使用session_start();启动会话session_start();

also check whether allow_url_fopen or allow_url_include or both have been set to 0 (disabled) in php.ini.还要检查是否在 php.ini 中将allow_url_fopenallow_url_include或两者都设置为 0(禁用)。 if yes try to activate it如果是,请尝试激活它

include "htmlheader.php";

instead of代替

include "http://www.mywebsite.com/htmlheader.php";

ensure you have session_start();确保你有session_start(); at the top of the page that is including the includesincludes的页面顶部

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

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