包括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

你好每一个我都对PHP有疑问。在我们的项目中,我们需要将所有的元素都包含在我们的索引中。 PHP。 所有页面的页眉和页脚都是相同的。但是主体应该根据每个页面的重定向而改变。根据我们的客户端,重定向应该仅在索引页面中发生。 因此我们不应该以下列方式使用 header(' location:login.php'); 我需要使用类似 header('location:index.php?getpage =“register.php”'); p>

并在索引页面中我们 需要检查条件 if(getpage包含值) { nirectirect to getpage url } else { nirectirect to login page } p>

但我的问题 是如何检查索引页面中的条件,如果我使用$ session的getpage它显示错误,没有声明getpage变量。请告诉解决方案我的问题 答案将非常感谢 p> div>

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