duan0821 2013-08-12 09:05
浏览 67
已采纳

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

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:

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:

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

htmlheader.php:

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

Output right now is:

test1:

test2:

(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

test2: homepagewhat the f_ck im scared

..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.

  • 写回答

2条回答 默认 最新

  • douri4459 2013-08-12 09:22
    关注

    Ensure that you have started the session with session_start();

    also check whether allow_url_fopen or allow_url_include or both have been set to 0 (disabled) in php.ini. if yes try to activate it

    include "htmlheader.php";
    

    instead of

    include "http://www.mywebsite.com/htmlheader.php";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机