我在本地服务器上多次运行这个脚本,没有问题。但是,当我将它们上传到网络服务器上时,我遇到了未定义的错误。我有点迷惑不解了。
问题是什么??
数据库表已定义。
本地 PHP 版本:5.3.5,Web 服务器上:5.3.26
我收到这些错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: username
Filename: models/user.php
Line Number: 7
A PHP Error was encountered
Severity: Notice
Message: Undefined index: password
Filename: models/user.php
Line Number: 8
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/caspian/domains/caspiansang.ir/public_html/system/core/Exceptions.php:185)
Filename: views/login.php
<p>Line Number: 1
控制器/验证登录.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class VerifyLogin extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}
function index()
{
$result = $this->user->validate();
if(! $result){
$data['msg'] = 'اطلاعات وارد شده اشتباه است!';
$this->load->view('login',$data);
}else{
redirect('admin');
}
}
}
模型/user.php
<?php
Class User extends CI_Model
{
public function validate(){
$username = $_POST['username'];
$password = $_POST['password'];
// Prep the query
$this->db->where('username', $username);
$this->db->where('password', md5($password));
// Run the query
$query = $this->db->get('admin');
// Let's check if there are any results
if($query->num_rows() == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'userid' => $row->userid,
'fname' => $row->fname,
'lname' => $row->lname,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
return false;
}
}
视图/login.php:
<?php echo form_open('verifylogin'); ?>
<br>
<div style="font-color:black; padding-bottom:10px;"> <?php if(! empty($msg)) echo $msg;?></div>
< label for="username">نام کاربری</label>
<input type="text" size="20" id="username" name="username"/>
<br/>
<label for="password">رمز عبور</label>
<input type="password" size="20" id="passowrd" name="password"/>
<br/>