php登录后怎么显示名字-PHP问题

资源魔 55 0

PHP session 变量用于存储对于用户会话(session)的信息,或许更改用户会话(session)的设置。Session 变量存储繁多用户的信息,而且关于使用顺序中的一切页面都是可用的。

咱们能够正在登录后应用PHP输入session中存储的用户名信息来完成php登录后显示名字。

保举:php效劳器

php登录后显示名字的办法:

登录表单:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Login</title>
</head>
<body>
    <form action="dologin.php" method="post">
 username:<input type="text" name="username" /><br/>
 password:<input type="password" name="password" />
        <input type="submit" value="提交"/>
    </form>
</body>
</html>

php登录代码:

dologin.php

<?php
    session_start();
    $username = $_POST['username']?$_POST['username']:'';
    $password = $_POST['password']?$_POST['password']:'';
    $link = mysqli_connect('localhost', 'root', 'root', 'test');
    mysqli_set_charset($link,'utf8');
    $sql = "select password from user_dologin where username='".$username."'";
    $res = mysqli_query($link,$sql);
    $result = mysqli_fetch_assoc($res);
 
    mysqli_close($link);
    if($result['password'] == $password){
        $_SESSION['username'] = $username;
        $_SESSION['password'] = $password;//普通状况下session中没有保留明码信息
        header("Location: index.php");
    }else{
        header("Location: login.html");//明码谬误跳回登岸网页
    }

登录后显示名字代码:

<?php
session_start();
echo "username:".$_SESSION['username']."<br/>";
echo "password:".$_SESSION['password'];

阅读器显示成果:

username:zhangsan
password:123456

以上就是php登录后怎样显示名字的具体内容,更多请存眷资源魔其它相干文章!

标签: php 登录 php教程 php故障解决 php使用问题

抱歉,评论功能暂时关闭!