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

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

报告相同问题?