我在Codeigniter中遇到了一个登录功能,该功能在localhost和我的测试服务器上运行,但是第三台服务器上的会话似乎没有设置。
这里是' home'的do_login功能。控制器:
public function do_login() {
if ($this->session->userdata('is_admin_login')) {
redirect('admin/home/dashboard');
} else {
$user = $_POST['username'];
$password = $_POST['password'];
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('admin/vwLogin');
} else {
$salt = '5&JDDGKGlwz%sRghewh!t2Yg-Igae@QxgakPzFTSId';
$enc_pass = md5($salt.$password);
$sql = "SELECT * FROM tbl_admin_users WHERE username = ? AND password = ?";
$val = $this->db->query($sql,array($user ,$enc_pass ));
if ($val->num_rows) {
foreach ($val->result_array() as $recs => $res) {
$sess_array = array(
'id' => $res['id'],
'username' => $res['username'],
'email' => $res['email'],
'is_admin_login' => true,
'user_type' => $res['user_type']
);
$this->session->set_userdata($sess_array);
}
redirect('admin/dashboard');
} else {
$err['error'] = '<strong>Access Denied</strong> Invalid Username/Password';
$this->load->view('admin/vwLogin', $err);
}
}
}
}
在所有3个地方(localhost,测试服务器和生产服务器),此功能重定向到&#39; admin / dashboard&#39;而且差别很大。 这是仪表板控制器:
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Dashboard extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
dump_exit($this->session->userdata);
if (!$this->session->userdata('is_admin_login')) {
redirect('admin/home');
}
}
public function index() {
$arr['page']='dash';
$this->load->view('admin/vwDashboard',$arr);
}
}
当我在构造函数中dump_exit会话数据时,&#39; is_admin_login&#39;是TRUE @ localhost和测试服务器但是它没有在生产服务器上设置。相同的代码。我试图修改$ config [&#39; cookie_domain&#39;],$ config [&#39; sess_expiration&#39;],我试图重新定位(&#39;网址&#39;,&#39; ;刷新&#39;)一切都没有成功...... 在autoload.php中我有:
$autoload['libraries'] = array('database', 'session', 'form_validation');
$autoload['helper'] = array('url', 'form', 'dump');
任何帮助或建议都将受到高度赞赏!