如果使用PHP登录,请更改整个站点
我正在创建一个仅用于学习目的的网站。我在index.php中这样做了。php是一个基本的登录表单。它是用MySQL设置的。我想这样做,当你没有登录时,你会在index.php中看到表单网站,当你登录时,你也会在index.php中看到一个完全不同的网站。我知道如何检查我是否登录,所以基本问题是:我可以做类似于这种风格的事情吗:如果使用PHP登录,请更改整个站点,php,coding-style,Php,Coding Style,我正在创建一个仅用于学习目的的网站。我在index.php中这样做了。php是一个基本的登录表单。它是用MySQL设置的。我想这样做,当你没有登录时,你会在index.php中看到表单网站,当你登录时,你也会在index.php中看到一个完全不同的网站。我知道如何检查我是否登录,所以基本问题是:我可以做类似于这种风格的事情吗: if(loggedIn){ include 'loggedInSite.php'; }else{ include 'notLoggedInSite
if(loggedIn){
include 'loggedInSite.php';
}else{
include 'notLoggedInSite.php';
}
还是必须完全不同?
或者我应该按照这些思路做点什么:
if(loggedIn){
echo "<html>Whole site</html>";
}
if(loggedIn){
呼应“整个网站”;
}
用一个简单的回显功能回显整个网站?您的第一个示例只需稍加修改即可正常工作:
if($loggedIn){
include 'loggedInSite.php';
}else{
include 'notLoggedInSite.php';
}
如果他们没有登录,为什么不直接将他们重定向到另一个页面 或 你写的应该有用
if($loggedIn){
include 'loggedInSite.php';
}else{
include 'notLoggedInSite.php';
}
我认为第一种方法看起来更好,尽管两种方法都应该有效。请使用
require
而不是include
,include建议不需要该文件(这种情况很少发生)。我知道这是psuedo代码但是。。在许多项目中都没有;]。这种方法可能比第二种方法更干净。如果两个页面都在同一个文件中,那么可能很容易站稳脚跟。