[ create a new paste ] login | about

Link: http://codepad.org/FILlq2qR    [ raw code | fork ]

PHP, pasted on Mar 3:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_management extends CI_Controller
{
    public function login ($use_cookies=true)
    {

        // LOAD LIBRARIES & HELPERS
        $this->load->library('session');
        $this->load->helper('cookie');
        $this->load->database();

        // GET DATA
        $s_logged = $this->session->userdata('logged');
        $s_email = $this->session->userdata('email');
        if($use_cookies)
        {
            $c_email = $this->input->cookie('email');
            $c_password = md5($this->input->cookie('password'));
        }
        $p_email = $this->input->post('email');
        $p_password = md5($this->input->post('password'));


        // SESSION CHECK
        if(!empty($s_logged) && !empty($s_email))
        {
            $login_data = array(
                'logged'    =>  true,
                'type'      =>  'session'
            );
        }
        // COOKIE CHECK
        elseif(!empty($c_email) && !empty($c_password) && $use_cookies)
        {
            $check_login = $this->db->query("SELECT * FROM users WHERE email = '".$c_email."' AND password = '".$c_password."'");
            $logged = (($check_login->num_rows > 0)? true : false);
            $login_data = array(
                'logged'    =>  $logged,
                'type'      =>  'cookie'
            );
        }
        // POST CHECK
        elseif(!empty($p_email) && !empty($p_password))
        {
            $check_login = $this->db->query("SELECT * FROM users WHERE email = '".$p_email."' AND password = '".$p_password."'");
            $logged = (($check_login->num_rows > 0)? true : false);
            if($logged && $use_cookies)
            {
                $c_email = array(
                    'name'   => 'email',
                    'value'  => $p_email,
                    'expire' => 86500,
                    'secure' => TRUE
                );
                $this->input->set_cookie($c_email);
                $c_password = array(
                    'name'   => 'password',
                    'value'  => $p_password,
                    'expire' => 86500,
                    'secure' => TRUE
                );
                $this->input->set_cookie($c_password);
            }
            // SET SESSION
            /*if($logged)
            {
                $s_data = array(
                    'logged' => TRUE,
                    'email'  => $p_email
                );
                $this->session->set_userdata($s_data);
            }*/
            $login_data = array(
                'logged'    =>  $logged,
                'type'      =>  'post'
            );
        }
        // REDIRECT
        else{
            $login_data = array(
                'logged'    =>  false
            );
        }
        return $login_data;
    }

    public function register ()
    {
        //$register_array;

    }
}


Create a new paste based on this one


Comments: