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 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入