我不斷收到此錯誤忽略的session_start:笨 - 一個會議已經開始了 - ()
A PHP Error was encountered
Severity: Notice
Message: A session had already been started - ignoring session_start()
Filename: Session/Session.php
Line Number: 140
在頁面上使用此代碼:
<body>
<p><a href="<?php echo site_url("Login_controller")?>">LOGIN</a><p>
<?php echo $this->session->userdata('Username'); ?>
</body>
沒有在session_start()上這一頁。
我能想到的唯一的事情已經引起了這是在autoload.php我已經做到了這一點:
$autoload['libraries'] = array('database','session');
是什麼原因造成這個錯誤?
編輯:登錄控制器
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Login_controller extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('User_model','',TRUE);
}
function index() //Default function that is run when this controller is called.//
{
$this->load->helper(array('form'));
$this->load->view('Login_view');
}
function Login()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('Username', 'Username', 'trim|required');
$this->form_validation->set_rules('Password', 'Password', 'trim|required|callback_CheckDatabase');
if($this->form_validation->run() == FALSE)
{
$this->load->view('Login_view'); //Reloads the login view with validation errors if the login attempt is unsuccessful.//
}
else
{
redirect('Home_controller'); //Redirect to the homepage on successful login attempt.//
}
}
function CheckDatabase($password) //This function is only run when password validation is correct.//
{
$username = $this->input->post('Username'); //Sets the username as a $username.//
$result = $this->User_model->Login($username, $password);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(//Makes an array of the data to be stored in the session.//
'UserID' => $row->UserID,
'Username' => $row->Username
);
$this->session->set_userdata('logged_in', $sess_array); //Sets $sess_array as the session.//
}
return TRUE;
}
else //Ran if the username or password aren't matched in the CIUsers database. Returns error message.//
{
$this->form_validation->set_message('CheckDatabase', 'Invalid login details.');
return false;
}
}
}
?>
發表您的控制器以及 –
編輯帖子包含控制器 – user3574766