登录时隐藏登录/注册按钮,注销时隐藏注销按钮 [英] Hide login/register button when logged in and hide logout button when logged out
本文介绍了登录时隐藏登录/注册按钮,注销时隐藏注销按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 PHP 新手,我遇到了一些问题.当我登录我的网站时,我想隐藏登录"和注册"按钮,当我退出时,我想隐藏注销"按钮.
这是我的 login.php 页面:
<?phpinclude_once "check.php";$error = "";//用于存储我们的错误的变量.if(isset($_POST["提交"])){if(empty($_POST["username"]) || empty($_POST["password"])){$error = "两个字段都是必填的.";}别的{//定义 $username 和 $password$用户名=$_POST['用户名'];$password=$_POST['密码'];//防止 MySQL 注入$username = stripslashes($username);$password = stripslashes($password);$username = mysqli_real_escape_string($db, $username);$password = mysqli_real_escape_string($db, $password);$password = md5($password);//从数据库中检查用户名和密码$sql="SELECT uid FROM users WHERE username='$username' and password='$password'";$result=mysqli_query($db,$sql);$row=mysqli_fetch_array($result,MYSQLI_ASSOC);//如果我们的数据库中存在用户名和密码,则创建一个会话.//否则回显错误.if(mysqli_num_rows($result) == 1){$_SESSION['username'] = $username;header("位置:index.php");}别的{$error = "用户名或密码不正确.";}}}?><头><link rel="stylesheet" type="text/css" href="assets/css/acc.css"><link rel="stylesheet" type="text/css" href="assets/css/acc2.css"><link rel="stylesheet" type="text/css" href="assets/css/navbar.css"><title>登录 |Peerbolte-ICT</title>头部><部分><p style="color:red;"><?php echo $error;?></p><form method="POST" action=""><div class="accPanel"><h1 style="color: black; padding-bottom: 5%;">登录</h1><form method="POST" action=""><div class="登录输入"><label class="accLabel"><b>用户名<span style="color:red;">*</span></b></label><input type="text" placeholder="输入用户名" name="username" required><label class="accLabel"><b>密码<span style="color:red;">*</span></b></label><input type="password" placeholder="输入密码" name="password" required><button class="submitButton" type="submit" name="submit">登录</button>
</表单>
</节>