我正在从Codeigniter 1.7.3升级到最新的2.2.0并遇到会话问题。 如果我使用名为 system / libraries / Session.php 的旧核心文件,但是如果我使用新的session.php文件,我的登录脚本根本不起作用。我的意思是在我尝试使用帐户和密码登录后它什么也没做。那么,最新版本的差异以及我的脚本应该是什么样子?感谢您花时间检查我的问题,并可能回答我!
编辑:我看到这两行引起了问题:
$this->session->sess_destroy(); $this->session->unset_userdata( array( 'logged' => false, 'users_id' => false, 'teams_id' => false, 'leader_teams_id' => false )
完整功能:
function login_do()
{
if ( $_POST['username'] && $_POST['password'] )
{
$user = $this->db->where( array( 'users_name' => trim( $_POST['username'] ), 'users_password' => sha1( md5( $_POST['password'] ) ) ) )->get( 'users' );
if ( $user->num_rows == '1' )
{
$user = $user->row();
$data = array( 'logged' => true, 'users_id' => $user->users_id );
if ( $user->users_teams_id > '0' )
{
$leader = $this->db->where( array( 'team_leader_id' => $user->users_id, 'teams_id' => $user->users_teams_id ) )->get( 'teams' )->row();
$data['teams_id'] = $user->users_teams_id;
if ( $leader )
$data['leader_teams_id'] = $user->users_teams_id;
}
$this->session->sess_destroy();
$this->session->unset_userdata( array( 'logged' => false, 'users_id' => false, 'teams_id' => false, 'leader_teams_id' => false ) );
$this->session->set_userdata( $data );
}
else
$this->session->set_flashdata( 'error', 'user_pass' );
}
else
$this->session->set_flashdata( 'error', 'data' );
redirect( 'home' );
}