【发布时间】: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