用户登录后,php change登录并注销 [英] php change sign in to sign out after user signs in

查看:197
本文介绍了用户登录后,php change登录并注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

signin.php:

signin.php:

<?php
include("config.php");

if (mysqli_connect_errno())
{
   echo "MySQLi Connection was not established: " . mysqli_connect_error();
}

if(isset($_POST['login']))
{
   $username = mysqli_real_escape_string($con,$_POST['username']);
   $password = mysqli_real_escape_string($con,$_POST['password']);

   $sel_user = "SELECT * FROM user WHERE username='$username' AND password='$password'";
   $run_user = mysqli_query($con, $sel_user);

   $check_user = mysqli_num_rows($run_user);

   if($check_user = 2)
   {
      $_SESSION['username']=$username;
      echo "<script>window.open('index.php','_self')</script>";
   }
   else 
   {
      echo "<script>alert('Email or password is not correct, try again')</script>";
   }
}

?>

index.php:

index.php:

<ul class="nav navbar-nav navbar-right">
     <li><a href="mypage.html">My Page</a></li>
     <li><a href="signup.php">Sign up</a></li>
     <li><a href="signin.php">Sign in</a></li>
</ul>

因此,我的index.php中有三个选项:我的页面",注册"和登录".我要更改登录以在用户登录时注销"并在我的页面"选项的左侧显示我的名字.如何修改我的代码?请不要只说您需要~~~".请指出确切添加的位置.谢谢

So, there are three options in my index.php, My Page, Sign up, and Sign in. I want to change Sign in to Sign out when user logs in and display my name on the left side of My Page option. How can I modify my codes? please don't just say "You need ~~~". please indicate where exactly add it as well. Thank you

推荐答案

代替

<li><a href="signin.php">Sign in</a></li>

您需要

<li>
    <?php
        if(isset($_SESSION['username'])) { ?>
            <a href="signout.php">Sign out</a>
    <?php 
        } else { ?>
            <a href="signin.php">Sign in</a>
    <?php
        } ?>
</li>


但是

那里存在大量的安全问题.从外观上看,您将密码以纯文本格式存储在数据库中. 您需要解决此问题.现在.


BUT

You have massive security issues there. You're storing passwords in plain text in your database, by the looks of it. You need to fix this. Now.

这篇关于用户登录后,php change登录并注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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