Вход Регистрация
Файл: tyde/www/application/controllers/Login.php
Строк: 23
<?php

class Login extends CI_Controller
{
    public function 
__construct ()
    {
        
parent::__construct();

        if (
$this->uauth->isAuth())
        {
            
header('location: /');
        }
    }

    public function 
index ()
    {
        if (
$this->input->post())
        {
            
$error = [];

            if (empty(
$_POST['login']))
                
$error[] = 'Вы не ввели логин';

            if (empty(
$_POST['password']))
                
$error[] = 'Вы не ввели пароль';

            if (empty(
$error))
            {
                
$data = [
                    
=> (string) $_POST['login'],
                    
=> (string) sha1($_POST['password'])
                ];

                
$query $this->db->query('SELECT `id` FROM `users` WHERE `login` = ? AND `password` = ?'$data);

                if (
$query->num_rows() > 0)
                {
                    
$user $query->row_array();
                    
$hash md5(time().$_POST['login'].$_POST['password']);

                    
$this->db->update('users', ['hash' => $hash], 'id = '.(int) $user['id']);

                    
setcookie('user_id'$user['id'], (time() + 24*60*60*365), '/');
                    
setcookie('sid'$hash, (time() + 24*60*60*365), '/');
                }
                else
                {
                    
$_SESSION['messages'] = ['Не верный логин или пароль'];
                }
            }
            else
            {
                
$_SESSION['messages'] = $error;
            }
        }

        
header('location: /');
    }
}
Онлайн: 0
Реклама