2017-02-27 33 views
0
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控制檯ERR消息那樣: 選項http://www.delikates.co.il/backend/checkSignIn網:: ERR_EMPTY_RESPONSE角2應用程序的響應是網:: ERR_EMPTY_RESPONSE

例外:響應,狀態:0的網址:空

未捕獲的響應{_body:ProgressEvent,狀態:0,OK:假,狀態文本: 「」,標題:頭...}

+0

當我通過簡單的HTML表單檢查,PHP程序進入重要的if語句:如果(password_verify($ jsonRequest->密碼,$ hashed_pa​​ssword)和($ email_verified)){ $ arr = $ delikatesDbConnect-> json_user_details($ id); $ jsonResponse = json_encode($ arr); $ response = new HttpResponse($ jsonResponse,202); 返回$ response; } –

回答

0

這好像和你是如何處理響應的問題。什麼是HttpResponse?

處理響應的典型方法是使用現有的響應對象並寫入該響應對象。

return $response->withJson($arr, 202); 

https://www.slimframework.com/docs/objects/response.html#returning-json

+1

thanx我的朋友,是不是在程序中進一步的問題,其中$迴應是? 。我最終確實從$ params中檢索了我想要檢索的內容。 –

+0

無論如何,我用你建議的命令替換了命令,但它不起作用。 –

+0

問題在於:if(password_verify($ jsonRequest-> password,$ hashed_pa​​ssword)和($ email_verified)) {echo「good」; $ arr = $ delikatesDbConnect-> json_user_details($ id); $ jsonResponse = json_encode($ arr); $ response = new HttpResponse($ jsonResponse,202); 返回$ response; } –