first commit
This commit is contained in:
44
application/controllers/User.php
Normal file
44
application/controllers/User.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class User extends CI_Controller {
|
||||
function __Construct()
|
||||
{
|
||||
parent ::__construct();
|
||||
$this->load->model('UserModel');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$location = site_url('welcome');
|
||||
header("Location: ".$location);
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
$data['username'] = $_POST['username'];
|
||||
$data['password'] = $_POST['password'];
|
||||
$result = $this->UserModel->login($data);
|
||||
if (isset($result)){
|
||||
$newdata = array(
|
||||
'username' => $result->username,
|
||||
'type' => $result->type,
|
||||
'logged_in' => TRUE
|
||||
);
|
||||
$this->session->set_userdata($newdata);
|
||||
$location = site_url('welcome');
|
||||
header("Location: ".$location);
|
||||
}else{
|
||||
$location = site_url('welcome');
|
||||
header("Location: ".$location);
|
||||
}
|
||||
}
|
||||
|
||||
public function logout(){
|
||||
$deldata = array('username','type','logged_in');
|
||||
$this->session->unset_userdata($deldata);
|
||||
$location = site_url('welcome');
|
||||
header("Location: ".$location);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user