| 제목 | session 만료 후 초기화면에 관한 질문 | ||
|---|---|---|---|
| 카테고리 | CI 2, 3 | ||
| 글쓴이 | 미나리나물 | 작성시각 | 2017/08/29 11:02:38 | 
| 
                         | 
                |||
| 
                         ci 책으로 게시판을 만들고 있는 학생입니다. 그런데 로그 아웃을 누르면 맨 처음 화면으로 정상적으로 로딩 되는데, 시간이 지나 세션이 스스로 만료되면 주소가 이상하게 나옵니다. 제가 사용하는 테스트 주소는 인데, 로그 아웃 클릭 시 저 주소로 정상 도달 합니다만, 자동 만료되면 주소가 http://192.168.10.10/auth/auth 로 나타납니다. 이 설정은 어디서 바꿔 줄 수 있는지요?  | 
                |||
| 다음글 | 검색기능시에 url은 변경되지만, 검색한 조건에 있는 ... (3) | ||
| 이전글 | input에서 사용하는 get()과 db에서 사용하는 ... (6) | ||
| 
                             
                                변종원(웅파)
                                /
                                2017/08/29 11:23:39 /
                                추천
                                0
                             
                            
                                컨트롤러와 config.php 파일의 $config['base_url'] 부분 올려주세요
                             
                         | 
                    
| 
                             
                                미나리나물
                                /
                                2017/08/29 11:29:53 /
                                추천
                                0
                             
                            $config['base_url'] = ''; 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 사용자 인증 컨트롤러
**/
class Auth extends CI_Controller {
  function __construct() {
    parent::__construct();
    $this -> load -> model('auth_m');
    $this -> load -> helper('form');
    $this -> load -> helper(array('url', 'date'));
    $this -> load -> helper('url');
  }
  public function index() {
    $this -> login();
  }
  /**
  * 로그인 처리
  **/
  public function login() {
    $this -> load -> library('form_validation');
    $this -> load -> helper('alert');
    $this -> form_validation -> set_rules('username', '아이디', 'required|alpha_numeric');
    $this -> form_validation -> set_rules('password', '비밀번호', 'required');
    echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
    if ($this -> form_validation -> run() == TRUE) {
      $auth_data = array(
        'username' => $this -> input -> post('username', TRUE),
        'password' => $this -> input -> post('password', TRUE),
      );
      $result = $this -> auth_m -> login($auth_data);
      if ($result) {
        $newdata = array(
          'username' => $result -> username,
          'userlevel' => $result -> userlevel,
          'logged_in' => TRUE
        );
        $this -> session -> set_userdata($newdata);
        // $this -> load -> view('main/main_v');
        redirect("/main/domain_w",'refresh');
      } else {
        alert('아이디 또는 비밀번호를 확인 해 주세요.', '/auth');
        exit;
      }
    } else {
      $this -> load -> view('auth/login_v');
    }
  }
  public function logout() {
    $this -> load -> helper('alert');
    $this -> session -> sess_destroy();
    echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
    alert('로그아웃 되었습니다.', '/auth');
    exit;
  }
}
?>
  | 
                    
| 
                             
                                변종원(웅파)
                                /
                                2017/08/29 14:41:47 /
                                추천
                                0
                             
                            로그인 체크하는 부분은 어떻게 되어 있을까요? 세션이 없으면 로그인 주소로 리다이렉트 할텐데 거기가 문제일거 같네요.  | 
                    
| 
                             
                                미나리나물
                                /
                                2017/08/29 15:37:49 /
                                추천
                                0
                             
                            
                                세션이 없어질 때 설정 부분은 어디에서 찾을 수 있을까요?
                             
                         | 
                    
| 
                             
                                변종원(웅파)
                                /
                                2017/08/29 15:43:06 /
                                추천
                                0
                             
                            
                                미나리나물/ 지금 책이 없어서 정확한 답변은 힘들지만 board 컨트롤러의 remap이나 write 메소드에 로그인 체크하는 부분이 있을 겁니다.
                             
                         | 
                    
| 
                             
                                미나리나물
                                /
                                2017/08/29 17:52:18 /
                                추천
                                0
                             
                            현재 몸통은 아래와 같습니다. 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends CI_Controller {
  function __construct() {
  parent::__construct();
  $this -> load -> database();
  $this -> load -> model('main_m');
  $this -> load -> helper(array('url', 'date'));
  $this -> load -> helper('url');
  $this -> load -> helper('alert');
  }
	public function index()
	{
		$this->load->view('main/domain_w');
	}
  public function _remap($method)
  {
    $this -> load -> view('header_v');
    if ( $this -> session -> userdata('userlevel') == "0" ) {
      $this -> load -> view('nav_admin_v.php');
    } else {
      $this -> load -> view('nav_user_v.php');
    }
    if (method_exists($this, $method)) {
      $this -> {"{$method}"}();
    }
    $this -> load -> view('footer_v');
  }
  public function domain_w() {
    $this -> load -> view('main/main_v');
  }
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
  | 
                    
| 
                             
                                미나리나물
                                /
                                2017/08/29 17:55:23 /
                                추천
                                0
                             
                            크아아아압!! 찾았습니다. 헤더에 있는 아래 부분이 문제 였습니다. 
<?php if (@$this -> session -> userdata('logged_in') == TRUE) { ?>
	            <div class="hdiv logout"><h3><?php echo $this -> session -> userdata('username'); ?></h3><span>님 환영합니다.</span><a href="/auth/logout" class="btn btn-info">로그 아웃</a></div>
			<?php
			} else {
				redirect("/auth",'refresh');
			}?>
여기서 redirect 부분에 "/auth"를 "/"로 바꾸니 정상 동작 합니다.  |