0

我在本地服务器上多次运行这个脚本,没有问题。但是,当我将它们上传到网络服务器上时,我遇到了未定义的错误。我有点迷惑不解了。

问题是什么??

数据库表已定义。

本地 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/>
4

5 回答 5

0

Remote server has display_errors option turned on and error_reporting option is set to include E_NOTICE.

The easy solution is to set display_errors to 0

The proper solution is to replicate server's settings on your local machine and fix the notices

于 2013-07-11T15:26:21.187 回答
0

The $_POST superglobal array may not be having the username and password set. To resolve this proble, you could check if they're set with isset():

if(isset($_POST['submit']))
{

//code block

}

Turning on error reporting will help you find out what's wrong with your script. To do that, add this to the top of your script:

ini_set('display_errors',1); 
error_reporting(E_ALL);

To set this globally, you can edit your php.ini file and change the error_reporting directive to the following:

error_reporting = E_ALL

The headers already sent error message usually caused by whitespace before <?php or after ?>. For a detailed explanation and helpful tips, see this StackOverflow answer.

Hope this helps!

于 2013-07-11T15:27:34.060 回答
0

您在一台服务器上关闭了 display_errors,在另一台服务器上又打开了。两台服务器上仍然存在这些问题,只是您没有在一台服务器上被告知它们。

问题是您在尝试使用它们之前正在访问未定义的变量或数组部分。

于 2013-07-11T15:24:01.433 回答
0

我找到了解决方案。这是因为在 htaccess 中启用了 mod_rewrite 导致 $_post 不起作用。

谢谢

于 2013-07-12T13:45:12.310 回答
0

也可以尝试使用codeigniters输入类$_POST['username'];你使用PHP原生post超全局变量试试看$this->input->post('username')这个问题是否解决

于 2013-07-12T12:13:49.060 回答