-1

我对我的 codeigniter 登录脚本有疑问。它不是很复杂,但效果很好。我的问题是,当用户登录时,他们会被重定向到我网站的另一部分,这是我想要的,但如果该用户注销,他们或(与此相关的任何人)仍然可以访问登录的 URL。如何使 URL 成为私有的?

例如,任何人都可以访问以下 URL。如何确保 URL 是私有的?mywebsite.com/_states/site/members_area

感谢大家

现场控制器

function validate_credentials()
{
  $this->load->model('model_data');
  $query = $this->model_data->validate_users();
   if($query){
      $data = array(
         'username' => $this->input->post('username'),
         'email' => 'johndoe@some-site.com',
         'is_logged_in' => TRUE
       );
       $this->session->set_userdata($data);

       redirect('site/members_area',$data);
   } else {
      $this->login();
   }

}

Model_data 扩展 CI_Model

function validate_users()
{
  $this->db->where('username', $this->input->post('username'));
  $this->db->where('password', md5($this->input->post('password')));
  $query = $this->db->get('members');

  if ($query->num_rows == 0){
   }

  if ($query->num_rows == 1){
      return true;
   } 
}

members_area 网址

<?php

echo 'Welcome!'.'<br>';

$session_id = $this->session->userdata('session_id').'<br>';
$whatever = $this->session->userdata('is_logged_in').'<br>';
$email = $this->session->userdata('email').'<br>';
$username = $this->session->userdata('username').'<br>';

echo 'This is the session ID = '."$session_id".'<br>';
echo 'This is the boolean, 1 means true = User Logged In = '."$whatever".'<br>';
echo 'This is the user "foo" email = '."$email".'<br>';
echo 'This is the user username = '."$username".'<br>';
echo anchor('site/logout', 'Logout!');


?>
4

1 回答 1

0

您需要检查是否设置了会话变量:

if($this->session->userdata('is_logged_in')) {
    // The user has logged in
}
于 2013-06-15T20:49:18.610 回答