저는 첫 번째 CI 프로젝트를 코딩하고 로그인 스크립트를 작성하려고합니다. 세션 userdata를 사용할 수 없다는 점을 제외하고는 거의 모든 것이 잘 작동합니다 (파이어 폭스에서 쿠키/세션을 확인하지 않아도).CodeIgniter Session Userdate가 존재하지 않는 것 같습니다.
세션 userdata가 로그인 후에 만 사용할 수있는 이유를 모르겠지만 동일한 페이지를 새로 고치면 (새로 고침이 아니라 새로드가 아닌) 계속 로그인 할 것으로 예상되지만, 내가 로그 아웃 했니? 세션 userdata를 읽으려고해도 그것이 존재하지 않습니다.
제 스크립트를 stackoverflow 용 예제 버전으로 단순화했습니다. 이 세션 문제가 어떻게 해결 될 수 있는지 누가 알 수 있습니까?
감사합니다, 귀도
<?php
class Test extends CI_Controller
{
function index()
{
$logged_in = $this->is_logged_in();
if($logged_in) {
echo "You are logged in. <a href='test/logout'>Logout</a> | <a href='../'>Return to index</a>";
}
else {
echo "You are logged out";
echo form_open('test/check_login');
echo "Email: ".form_input('email', set_value('email'));
echo "Password: ".form_password('password', set_value('password'));
echo form_submit('submit','Login');
echo form_close();
}
}
function is_logged_in() // check if user has logged in
{
// AUTOLOAD SESSIONS HAS SET in autoload.php-config >> $autoload['libraries'] = arra y('database', 'session', 'email');
$is_logged_in = $this->session->userdata('is_logged_in');
if($is_logged_in) {
return TRUE;
}
else {
return FALSE;
}
}
function check_login()
{
$client_id = $this->validate();
if(is_numeric($client_id)) // if the user's credentials validated then user exists
{
$data = array(
'client_id' => $client_id,
'is_logged_in' => true
);
$this->session->set_userdata($data);
}
$this->index();
}
// normally we put this function in a model, but for this example we put it here.
function validate() // check if user exists in database
{
$this->db->where('email', $this->input->post('email'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('client_users'); // this is our user table
if($query->num_rows == 1) // user exists
{
$row = $query->row();
return $row->id_client;
}
else
{
return false;
}
}
function logout()
{
$this->session->sess_destroy(); // kill session, so user will be logged out.
redirect('/test');
}
}
?>
글쎄, 뭔가가있는 것 같습니다. 내 localhost에서 '세션'을 사용하여 잘못되었습니다 ...하지만 문제가 어디서 시작하는지 모르겠습니다. –
나는이 문제를 해결했다 ... 그것은 'localhost 일이야. 내가 localhost에서 테스트했기 때문에 CI의 도메인 설정이 비어 있어야만하는 것 같다. (http://codeigniter.com/forums/viewthread/209191/ 참조) –