请放心,这可能只是一个简单的解决方法,但是我已经坚持了好几天。
我一直在获取未定义的变量。用户登录后将无法使用。我不确定我是在正确使用会话还是忘记代码。
panel.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Panel extends CI_Controller {
public function index()
{
$this->load->view('login');
}
public function login(){
$this->load->model('user_model');
$username = $this->input->post('username');
$password = strtoupper(sha1($this->input->post('password')));
$user_id = $this->user_model->login($username, $password);
if($user_id){
$user_data = array(
'user_id' => $user_id,
'username' => $username,
'logged_in' => true
);
$this->session->set_userdata($user_data);
redirect('panel/home');
} else {
redirect('');
}
}
public function home(){
$this->load->view('welcome_message');
}
}
welcome_message.php
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<p><?php echo $username; ?></p>
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>
错误
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: username
Filename: views/welcome_message.php
Line Number: 75
Backtrace:
File: C:\xampp\htdocs\application\views\welcome_message.php
Line: 75
Function: _error_handler
File: C:\xampp\htdocs\application\controllers\panel.php
Line: 29
Function: view
File: C:\xampp\htdocs\index.php
Line: 315
Function: require_once
这是我不断收到的错误