login.php 1.2 KB
<?php
namespace count_form\app\data;
class login
{
    protected  $name;
    protected $password;

    function index()
    {
        if(isset($_POST['name']) && isset($_POST['password'])){
            $name =  htmlspecialchars($_POST['name']);
            $password = htmlspecialchars($_POST['password']);
            $check = $this->checkUser($name, $password);
            if($check){
                $this->regUser();
            } else {
                header("Location:/count_form.php/?p=login");
            }
        }

    }

    function createUser()
    {
        $this->name = 'form_admin';
        $this->password = 'qwerty';
    }

    function checkUser($name, $password)
    {
        $this->createUser();
        if($this->name = $name){
            if($this->password = $password)
            {
                return true;

            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    function regUser(){
        if(session_id()){
            $_SESSION['form_admin'] = true;
        } else {

            session_start();
            $_SESSION['form_admin'] = true;
        }
    }


}