dprfe04886 2014-06-14 12:07
浏览 39
已采纳

包括PHP中的会话变量的不同网页

Hello every one I have a doubt in php .IN our project we need to include all the palges into our index.php. Header and footer are same for all the pages.But body should change as per the redirecting of each page.And according to our client that redirection should happen in index page only. So we should not use in the following manner header('location:login.php'); we need to use like header('location:index.php?getpage="register.php"');

and in index page we need to check the condition if(getpage contains value) { redirect to getpage url } else { redirect to login page }

But my problem is how to check the condition in index page if Iam using $session of getpage it is showing error that getpage variable is not declared.Please tell solution for my problem Answer will be highly appreciated

  • 写回答

1条回答 默认 最新

  • 普通网友 2014-06-14 12:17
    关注

    do you have

    session_start();

    at the top of your php code before any other php on the page?

    Without this you'll lose your session variables from page to page.

    What you desire to do is change just the body of the page using a $_GET or $_SESSION variable, so in the tag you want <? include ($_GET['getpage] . ".inc.php") ?>

    So if you pass index.php?getpage=register

    it will include register.inc.php in your body content.

    Please note if you're dealing with anything important you might want to escape out special chars etc, but I'm just answering the question.

    If you want to override it with a session variable then I'd do something like this

    if($_SESSION['getpage']) {$getpage = $_SESSION['getpage'];} else { if($_GET['getpage']) {$getpage = $_GET['getpage'];} else {$getpage ='home';}}
    

    then call <? include($getpage) . ".inc.php") ?> in your body

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图