php learning --session

1 Overview

In these days do a statistical internal management system, all need to be logged in to view the contents. This requires each module has an internal system login authentication function. Information on the Internet to find a circle, decided to do a session.

2, System Overview

Rear Language: php (using native php, without introducing frame)

Front-end style: Bootstrap

The main functions: basic functions of administrator, general users need to be unified management by the administrator. Ordinary users can view statistics, user administrators can only sign in center administrators to manage users.

3, session using

a, after a successful login you need to create and record session

<?php

    require "../DB/MySQLHelper.php";
    require "../BLL/UserBLL.php";
    $result = -1;
    if(count($_POST)!=2)
    {
        echo $result;
        return;
    }
    $name = $_POST["name"];
    $password = $_POST["password"];

    $helper = new MySQLHelper();
    $helper->InitMySQL();
    $level = SelectUserLevel($helper,$name,$password);
    if($level != -1)
    {
        $result = $level;
        session_start();
        $_SESSION["user"] = true;
        $_SESSION["name"]=$name;
        $_SESSION["pwd"]=$password;
    }
    echo $result;
?>

b, using session specific methods other functional modules, wrote a generic php, other modules before calling the first call to determine whether php login.

<?php
    $user = false;
    session_start();
    //  判断是否登陆
    if (isset($_SESSION["user"]) && $_SESSION["user"] === true) {
        echo "true";
    } 
    else {
        $_SESSION["user"] = false;
        echo "false";
    }

?>

4, summary

The system functions as a whole is relatively simple, mainly familiar sign in the entire process.

Guess you like

Origin www.cnblogs.com/syyjoy/p/10951129.html