| 제목 | view에서 session 정보 가져오기 | ||
|---|---|---|---|
| 카테고리 | CI 2, 3 | ||
| 글쓴이 | Givepro | 작성시각 | 2016/12/02 09:28:32 |
|
|
|||
|
어제부터 아무리 봐도 이해가 되질 않는부분이있어서 질문을 올립니다.. ci_sessions을 이용해서 로그인까지 구현은 했습니다. 물론 로그아웃도 되고 세션이 db table인 ci_sessions에 들어오는것까지 확인했습니다. 세션이 없으면 로그인페이지로 이동하게끔 처리를 해놔서 세션이 확실하게 들어오는것은 확인했습니다. 그런데
<?php if ( @$this -> session -> set_userdata('logged_in') == TRUE) { ?> <?php echo $this -> session -> userdata('user_id');?> <?php } ?>
이 구문을 view단에서 사용하려고하면 내용이 보이지않습니다... user_id 값이 admin이기때문에 admin이 나와야 하는게 정상인데 왜 나오지않는지를 모르겠습니다. 분명 세션은 들어가있는데...
view에서는 template를 사용해서 tpl파일을 사용하고있습니다. 혹시 이게 문제가 있는건가요? 참고로 config의 세션 설정은 $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_expire_on_close'] = FALSE; $config['sess_encrypt_cookie'] = FALSE; $config['sess_use_database'] = TRUE; $config['sess_table_name'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = TRUE; $config['sess_time_to_update'] = 300; 세션 설정값은 전부 TRUE로도 해봤는데 똑같습니다... 밑에는 로그인 처리 메소드입니다.
/*
* 로그인 처리
*/
public function login() {
$this->tpl->define('content', '/index.tpl');
// Form validation 라이브러리 로드 ( 폼 검증 라이브러리 로드)
$this->load->library('form_validation');
//보안 헬퍼 로딩
$this->load->helper('security');
// 폼 검증 필드와 규칙 사전 정의
$this -> form_validation -> set_rules('user_id', '아이디', 'required|alpha_numeric');
$this -> form_validation -> set_rules('user_password', '비밀번호', 'required');
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
if ($this -> form_validation -> run() == TRUE) {
$auth_data = array(
'user_id' => $this -> input -> post('user_id'),
'user_password' => md5($this -> input -> post('user_password')),
);
$result = $this -> keunsik_model -> login($auth_data);
if ($result) {
$newdata = array(
'user_id' => $result -> user_id,
'user_name' => $result -> user_name,
'logged_in' => TRUE
);
$this -> session -> set_userdata($newdata);
alert('로그인 되었습니다.', '/keunsik/board_list');
exit;
} else {
alert('아이디와 비밀번호를 확인해 주세요.', '/keunsik');
exit;
}
} else {
$this->tpl->print_('content');
}
}
도와주세요 ㅜㅜ |
|||
| 다음글 | CI에서 model 호출관련 오류 질문입니다. (10) | ||
| 이전글 | CI를 설치하고 싶습니다. (1) | ||
| 없음 |