【发布时间】:2017-07-18 08:46:45
【问题描述】:
Hi everyone,
this is the code in slim php:
$app->post('/checkSignIn', function () use ($app) {
$params = $app->request->post()['body'] ;
if(!empty($params))
{
$jsonRequest = json_decode($params);
//echo $jsonRequest->email;
$delikatesDbConnect = new DelikatesDbConnect ('localhost', 'gontar_delikates', 'DgDgDg11', 'gontar_delikates');
$id = $delikatesDbConnect->findUserIdByMail($jsonRequest->email);
//echo $id;
if ($id>0) // if $id exists fetch hashed password and email_verfied values
{
$hashed_password = $delikatesDbConnect->findPasswordById($id);
$email_verified = $delikatesDbConnect->findEmailVerifiedById($id);
if (password_verify($jsonRequest->password,$hashed_password) and ($email_verified))
{
$arr = $delikatesDbConnect->json_user_details($id);
$jsonResponse = json_encode($arr);
$response = new HttpResponse($jsonResponse,202);
return $response;
}
else
{
return '';
}
}
else
{
return '';
}
}
else
{
return '';
}
})->name('register');
this is the request code in typscript ng2:
sendUserAndPass(userDetails:JSON)
{
const body = JSON.stringify(userDetails);
console.log(body);
const headers = new Headers();
headers.append('Content-Type','application/json');
this.http.post("http://www.delikates.co.il/backend/checkSignIn", body, {headers: headers})
.subscribe((data:Response)=>console.log(data));
}
为什么我会收到这样的 chrome 控制台错误消息: 选项http://www.delikates.co.il/backend/checkSignInnet::ERR_EMPTY_RESPONSE
例外:响应状态为:0,URL 为空
未捕获的响应 {_body: ProgressEvent, status: 0, ok: false, statusText: "", headers: Headers...}
【问题讨论】:
-
当我通过简单的 html 表单检查时,php 程序输入了重要的 if 语句: if (password_verify($jsonRequest->password,$hashed_password) and ($email_verified)) { $arr = $delikatesDbConnect ->json_user_details($id); $jsonResponse = json_encode($arr); $response = new HttpResponse($jsonResponse,202);返回$响应; }