I use the following code to check some of the cases described in the comments. Unfortunately, it has come down page load speed. To improve the function and use them properly, what do you suggest, what do I do?
function insert() {
if ($this - > session - > userdata('logged_in')) { //This is for test whether the user is logged in or not?
if ($this - > siran - > access_level_active()) { //This is because the user name manager is active or not?
if ($this - > siran - > access_level('1', '5')) { //This is for whether or not permission to access this page?
if($_POST){
$this - > load - > view('admin/onepage');
}else{
$this->session->set_flashdata('message_p', $this->lang->line('nopost'));
redirect($this->session->userdata('previous_page'));
}
} else {
$this - > session - > set_flashdata('message', $this - > lang - > line('notaccess'));
redirect($this - > session - > userdata('previous_page'));
}
} else {
$this - > session - > set_flashdata('message', $this - > lang - > line('noactive'));
redirect('login', 'refresh');
}
} else {
$this - > session - > set_flashdata('message', $this - > lang - > line('plslogin'));
redirect('login', 'refresh');
}
}
These three functions in library codeigniter:
public function access_level($mp, $access){
//$mp = '1';
$CI = &get_instance();
$result = $CI->db->get_where('access_level', array('mainpage'=>$mp,'id_relation'=>$CI->session->userdata('id_relation')));
$data = array();
$out = array();
foreach($result->result() as $row){
$dv = json_decode($row->subpage);
$flat = array();
foreach ( $dv as $item ) {
$flat = array_merge( $flat, explode( ',', $item ) );
}
$out = array_merge( $out, $flat );
}
if(in_array($access, $out) || in_array('110', $out)){
return true;
}else{
return false;
}
}
public function access_level_active(){
//$mp = '1';
$CI = &get_instance();
$result = $CI->db->get_where('users', array('id'=>$CI->session->userdata('id')));
if ($result->num_rows() > 0){
$row = $result->row();
return ($row->active == 1 ? true : false );
}else{
return false;
}
}
function previous_page(){
$CI = &get_instance();
if ($CI->session->userdata('logged_in')) {
if (isset($_SERVER['HTTP_REFERER']))
{
$CI->session->set_userdata('previous_page', $_SERVER['HTTP_REFERER']);
}else
{
$CI->session->set_userdata('previous_page', base_url());
}
}
}