php – 消息:ini_set():会话处于活动状态.您目前无法更改会话模块的ini设置

前端之家收集整理的这篇文章主要介绍了php – 消息:ini_set():会话处于活动状态.您目前无法更改会话模块的ini设置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我用codeigniter创建了一个登录页面,但是我收到了PHP消息.

消息:ini_set():会话处于活动状态.您目前无法更改会话模块的ini设置

怎么解决这个问题?

查看(login.PHP)

<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<title>Admin Login</title>
<link rel="stylesheet" href="../css/normalize.css">
<link rel="stylesheet" href="../css/admin-style.css">
</head>
<body>
    <?PHP echo form_open('Verify_login',['id'=>'loginForm','name'=>'loginForm','method'=>'post']) ?>
    <div class="login">
        <div class="log-Box">
            <h3>Login</h3>
            <div >
                  <input id="username" name="username" placeholder="User Name" value="" type="text" >
                <?PHP echo form_error('username'); ?>
                <input id="Password" name="password" placeholder="Password" required type="password">
                <?PHP echo form_error('password'); ?>
                <div class="remember-me">
                    <input id="checkBox" type="checkBox">
                    <label for="checkBox">Remember Me</label>
                </div>
                <button class="login-button" name="loginButton">Login</button>
            </div>
        </div>
    </div>
 </form>
</body>
</html>

控制器(Verify_login.PHP)

<?PHP 
defined('BASEPATH') OR exit('No direct script access aloowed');

class Verify_login extends CI_Controller
{

public function __construct()
{
    parent::__construct();
    $this->load->model('User');
    $this->load->helper('url');
    $this->load->helper('security');
    $this->load->library('form_validation');
    $this->load->library('session');
}

public function index()
{
    $this->form_validation->set_rules('username','Username','trim|required');
    $this->form_validation->set_rules('password','Password','trim|required|callback_check_database');
    if ($this->form_validation->run() == FALSE) {
        // if validation Failed load the view 
        $this->load->view('admin/login');
    }

    else{
        $this->check_database($username,$password);
        redirect('dashboard','refresh');
    }
}

public function check_database($password)
{
    $username = $this->input->post('username');

    //query tha database
    $result = $this->User->login($username,$password);

    if ($result) {
        $sess_array = [];
        foreach ($result as $row) {
            $sess_array = 
                [
                    'id'=>$row->id,'username'=>$row->name
                ];
            $this->session->set_userdata('logged_in',$sess_array);
        }
        return TRUE;
    }
    else{

        $this->form_validation->set_message('check_database','invalid username and password');
    }
  }
 }
?>

控制器(admin.PHP的)

session_start(); //need to call PHP's session object to access it though it
class Admin extends CI_Controller
{

public $data;
public function __construct()
{
    parent::__construct();
    $this->load->helper('url');

    $this->load->helper('form');
    $this->load->helper('url');
    $this->load->library('form_validation');
    $this->load->helper('security');

    //load user model
    $this->load->model('User');

}
public function index()
{
    // $this->load->view('admin/index');
    if ($this->session->userdata('logged_in')) {

        $session_data = $this->session->userdata('logged_in');
        $data['username'] = $session_data['name'];
        $this->load->view('admin/dashboard',$data);
    }
    else{

        //if no session redirect to login page 
        redirect('admin','refresh');
        // redirect('login');
    }
}

public function logout()
{
    $this->session->unset_userdata('logged_in');
    session_destroy();
    redirect('home','refresh');
}

model(User.PHP)

<?PHP

/ **
*用户登录claass,扩展了MY_Model
*
* /

defined('BASEPATH') OR exit('no direct script allowed');

class User extends CI_Model
{
    protected $table = 'users';

    public function __construct()
    {
        $this->load->database();
    }

    public function login($username,$password)
    {
        var_dump($username);
        var_dump($password);
        $this->db->select(['id','name','password']);
        $this->db->from($this->table);
        // $this->db->where('name',$username);
        // $this->db->where('password',$password);
        $this->db->limit(1);

        $query = $this->db->get();
        if ($query->num_rows() == 1) {
            return $query->result();
        }
        else{

            return false;
        }
    }
   }    
   ?>
我认为你是框架概念和OOP的新手.

你在admin.PHP中不需要这一行

session_start(); //need to call PHP's session object to access it though it

当您加载会话库时,它的构造函数会为您执行这些操作.

原文链接:https://www.f2er.com/php/132614.html

猜你在找的PHP相关文章