首先,我想告诉您,我进行了很多搜索,但找不到解决方案。无论如何,第一件事首先是我是CI的新手,我尝试使用CI会话创建一个以CI内置的登录页面。我的登录控制器功能看起来像这样
//Validating login from ajax request
function validate_login() {
$email = $this->input->post('email');
$password = $this->input->post('password');
$credential = array('email' => $email, 'password' => sha1($password));
// Checking login credential for admin
$query = $this->db->get_where('admin', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$_SESSION['admin_login'] = '1'; // I am using traditional PHP Session Global Variable for Setting Session Variable
$_SESSION['admin_id'] = $row->admin_id;
$_SESSION['login_user_id'] = $row->admin_id;
$_SESSION['name'] = $row->name;
$_SESSION['login_type'] = 'admin';
//echo $this->session->userdata('admin_login');exit; //This is printing the data fine
redirect(base_url() . 'index.php?admin/dashboard');
}
现在将其重定向到管理控制器仪表板功能
/***ADMIN DASHBOARD***/
function dashboard()
{
echo "<pre>";
print_r($_SESSION); exit;
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
$page_data['page_name'] = 'dashboard';
$page_data['page_title'] = get_phrase('admin_dashboard');
$this->load->view('backend/index', $page_data);
}
输出
Array
(
[__ci_last_regenerate] => 1530080373
)
我的Autoload.php
$autoload['libraries'] = array('pagination', 'xmlrpc' , 'form_validation', 'email','upload','paypal','session','database');
我也试图在Admin的构造函数上加载会话库
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('Barcode_model');
$this->load->model('session');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
}
但是由于我无法登录并重定向到],似乎没有任何作用>
if ($this->session->userdata('admin_login') != 1) redirect(base_url(), 'refresh');
Config.php
$config['sess_driver'] = 'database'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_save_path'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 7200; $config['sess_regenerate_destroy'] = TRUE; /* |-------------------------------------------------------------------------- | Cookie Related Variables |-------------------------------------------------------------------------- | | 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions | 'cookie_domain' = Set to .your-domain.com for site-wide cookies | 'cookie_path' = Typically will be a forward slash | 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists. | 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) | | Note: These settings (with the exception of 'cookie_prefix' and | 'cookie_httponly') will also affect sessions. | */ $config['cookie_prefix'] = ''; $config['cookie_domain'] = 'localhost'; $config['cookie_path'] = '/'; $config['cookie_secure'] = FALSE; $config['cookie_httponly'] = FALSE; /*
我要设置的部分缺少任何内容吗?帮助表示赞赏。
首先,我想告诉您,我进行了很多搜索,但找不到解决方案。无论如何,第一件事首先是我是CI的新手,并且我尝试使用CI会话创建以CI内置的登录页面。...
php 7.1上的3.0.1版本的会话存在问题