【问题标题】:can't read $_POST data in PHP 5.6.3无法在 PHP 5.6.3 中读取 $_POST 数据
【发布时间】:2015-07-14 03:15:25
【问题描述】:

在过去的几个月里,我尝试在没有任何框架的情况下使用 php 编写小型 API,当我尝试读取 $_POST 数据时遇到了一个虚拟错误,我想可能是我在代码中犯了错误,或者我的本地主机有一个问题,因为我的代码在我的服务器上上传时工作正常,所以我忽略了它,现在我在项目中工作,我使用 codeigniter,我使用我的旧代码,我对参数名称等进行了一些更改。

完成所有操作后,我尝试在本地主机中进行测试,当我尝试读取$_post 数据时,它总是为空!!。我尝试将它上传到我的服务器上,它工作正常!!!

所以我在我的服务器和本地主机中检查了我的 php 版本,我发现我的服务器使用 php 5.4 而我的本地主机在 5.6.3 上运行!

这个问题有什么解决办法吗?有人遇到同样的问题吗?

例子:

    function user_signin_post()
    {
        $this->load->library('form_validation');

        //save the input in variables
        $username = $this->security->xss_clean($this->input->post('username'));
        $password = $this->security->xss_clean($this->input->post('password'));

       // form_validation all the fields are not empty
       $this->form_validation->set_rules('username', 'username', 'required');

       if ($this->form_validation->run() == FALSE)
       {
           $result = array('status' => $this->input->post(),'Error_Number' => 121,'Error_Message' => 'dont miss username fild.');
           $this->response($result);

        }else
        {
            $this->form_validation->set_rules('password', 'password', 'required');
            if ($this->form_validation->run() == FALSE)
            {
                 $result = array('status' => 0,'Error_Number' => 122,'Error_Message' => 'dont miss password fild.');
                 $this->response($result);

             }else
             {
                  // load the user model
                  $this->load->model('users_model');
                  $this->load->model('security_model');

                 // use the signin function
                 $query = $this->users_model->user_signin($username, $password);
                 $session_key = $this->security_model->create_user_session($query);
                 $array = array('user_id' => $query, 'session_key' => $session_key);
                 $this->response($array, 200);

           }//end 2nd if
    }//end 1st if

我总是得到:

{
"status": [],
"Error_Number": 121,
"Error_Message": "dont miss username fild."
 } 

我尝试打印 $_POST 数据,但它是空的

【问题讨论】:

  • 你发帖怎么样?通过表单发布或 AJAX 调用?
  • 在您的帖子中添加代码??
  • @Schien 我使用 codeigniter 所以它是$this->input->post('password')
  • 发送部分呢?只是一个常规的形式?也可以在单独的测试文件中尝试 $_POST,只是为了忽略来自 CI 的任何干扰
  • @Schien 我使用 rest 客户端发帖,因为我构建了一个 api

标签: php codeigniter post


【解决方案1】:

您应该向我们展示一些带有错误消息的代码。

由于您使用 codeigniter 作为框架,请使用 $this->input->post(); 你有两个选择: 1- 用于调试使用die(print_r($this->input->post())); 这将显示所有已发布的值。 2- 使用$this->input->post('post_name'); 检索单个值。

【讨论】:

  • 总是得到{ "status": 0, "Error_Number": 121, "Error_Message": "dont miss username fild." }
  • @csbukhari 好的,用于结构化调试过程;在你的函数function user_signin_post() { 的开头添加die(print_r($this->input->post()));,然后再做任何其他事情。并显示输出。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多