如何在此代码中使用Session。无法理解

时间:2019-04-25 09:53:12

标签: php

我正在尝试在此基本登录页面中使用Session。我在哪里以及如何使用Session?谢谢。我看到了许多使用会话的示例,但请指出可以在何处添加会话。我是PHP编码的新手。

<!DOCTYPE html>
<html>
<head>

        <title>Login Page</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>

 <h1><b><center> Login Form</center></b></h1><br>

                <form method="post" action="loginn.php">

                <!--class in css can be defined and used here. need to check how?-->    
                <center><input type="tel" class="form-control" name="Mobile_No" placeholder="Please enter your Mobile No" required="true"  style='width:30em' pattern="[0-9]{10}">

                <br><br>
                <center> <input type="password" class="form-control" name="Password" placeholder="Please enter password here" required="true" style='width:30em' >
                <br><br>
                <center>  <input type="submit" class="btn btn-primary" value="Login">
                </form> 

            <br><br><br><br>


<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

在您的loginn.php页面中。在页面顶部开始会话。像

session_start();//this

然后搜索输入Mobile_No并在数据库中输入密码(如果找到),然后分配会话变量user_id,如

$_SESSION['user_id'] = $user->ID;

注意:如果任何页面已经具有session_start();功能,则编写ob_start();功能。