如何在PHP中的HTML页面中动态更改登录和注销链接? [英] How to change login and logout links dynamically in HTML page in PHP?

查看:127
本文介绍了如何在PHP中的HTML页面中动态更改登录和注销链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML代码。我有2个PHP文件:login.php和logout.php。当任何用户首次访问我的页面时,我希望他看到登录链接。点击登录(我将用我的login.php文件处理)后,我想要将该登录链接更改为注销(并单击该logout.php文件将被处理)。

I have the following HTML code. I have 2 php files: login.php and logout.php. When any user first comes to my page, I would like him to see the login link. After clicking log in (which I will process with my login.php file) I want to change that login link to logout (and on click of that logout.php file will be processed)

在下面的代码中,我如何动态更改登录和注销链接?

In the following code, how could I dynamically change login and logout links? Currently I have given 2 different links for login and logout which is not a good idea.

<header class="group">
    <nav class="group">         
        <ul>
          <li><a href="register.php" title="">Register</a></li>
          <li><a href="login.php" title="">Login</a></li>   
              <li><a href="logout.php" title="">Logout</a></li>             
        </ul>
    </nav>
</header>


推荐答案

我假设您正在使用会话来检查是否用户是否登录。如果没有,请创建一个会话变量并设置一次登录。在注销时清除会话变量。所以你可以检查

I am assuming you are using a session to check whether user logged in or not. If not, create a session variable and set once logged in. Clear the session variable on log out. So you can check

if(isset($_SESSION['logged_in'])){
//your logout link
}else{
//your login link
}

这篇关于如何在PHP中的HTML页面中动态更改登录和注销链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆