如何在web服务器中无错误地调用angular和Php应用程序的api?

如何在web服务器中无错误地调用angular和Php应用程序的api?,php,angular8,Php,Angular8,我是web部署新手,我已经构建了angular 8和 PHP7应用程序,我托管了它们。在本地,所有api调用都有效,但 部署后出现错误,如状态500,甚至没有一个api TLS服务器上的调用工作 下面是一些代码: <?php $json = file_get_contents('php://input'); $decoded = json_decode($json); $email = htmlspecialchars($decoded->email, ENT_QUOTES); $p

我是web部署新手,我已经构建了angular 8和 PHP7应用程序,我托管了它们。在本地,所有api调用都有效,但 部署后出现错误,如状态500,甚至没有一个api TLS服务器上的调用工作

下面是一些代码:

<?php
$json = file_get_contents('php://input');
$decoded = json_decode($json);
$email = htmlspecialchars($decoded->email, ENT_QUOTES);
$pass = htmlspecialchars($decoded->password, ENT_QUOTES);
function conn()
{
    $dbhost = "localhost";
    $user = "root";
    $pass = "";
    $db = "smart";

    $conn = new PDO('mysql:host=91.134.248.250;dbname=smart', $user,
        $pass);
    return $conn;
}

function encrypt_decrypt($action, $string)
{
    $output = FALSE;
    $encrypt_method = "AES-256-CBC";
    $secret_key = 'WS-SERVICE-KEY';
    $secret_iv = 'WS-SERVICE-VALUE';
    $key = hash('sha256', $secret_key);
    $iv = substr(hash('sha256', $secret_iv),
        0, 16);
    if($action == 'encrypt') {
        $output =
            base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0,
                $iv));
    } else {
        if($action == 'decrypt') {
            $output =
                openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0,
                    $iv);
        }
    }
    return $output;
}

if(empty($email) || empty($pass) || mb_strlen($pass) < 6 || mb_strlen($pass) > 30) {
    json_encode(FALSE);
    die;
} else {
    $db = conn();
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $password = encrypt_decrypt('encrypt', $pass);
    $res = $db->prepare("SELECT * FROM user WHERE email = ? and password = ? ");
    $res->execute([$email, $password]);
    $values = $res->fetchAll();
    echo json_encode(sizeof($values) > 0 ? TRUE : FALSE);
}
?>
[![在此处输入图像描述][1][1]

[1] :


500错误是一个通用的错误消息,几乎涵盖了PHP脚本可能出现的每一个错误。请检查服务器错误日志以了解确切的错误消息。不要修改/转义用户密码。您将彻底更改用户想要的密码。而是在存储和验证时使用。我认为问题在于服务器规则
 import { Component, OnInit, OnDestroy } from '@angular/core';
 import { FormGroup, Validators, FormControl } from '@angular/forms';
 import { HttpClient } from '@angular/common/http';
 import { User } from '../models/user.model';
 import { UserService } from 'app/services/user.service';
 import { Inject, Injectable } from '@angular/core';
 import { AuthService } from '../services/auth.service';
 import { NgxUiLoaderService } from 'ngx-ui-loader';
 import { LocalStorageService } from 'ngx-localstorage';
 import { Subscription } from 'rxjs/Subscription';
 import { filter, map } from 'rxjs/operators';
 import { AlertService } from 'ngx-alerts';
 import { Router } from '@angular/router';
 @Component({
 selector: 'app-connecter',
 templateUrl: './connecter.component.html',
 styleUrls: ['./connecter.component.scss']
 })
 export class ConnecterComponent implements OnInit, OnDestroy {
 onSubmit() {
 let email = this.AuthForm.get('email').value;
 let password = this.AuthForm.get('password').value;
 let nomcomplet = '';
 let occupation = '';
 let newUser = new User(email, password, nomcomplet, occupation, '');
 console.log(newUser);
 this.httpSubscription = this.http.post("http://www.smartlibrairie.com/SmartLibrary/api/logins.php",

 JSON.stringify(newUser)).subscribe(res => {
 console.log(res);
 if (res === true) {
 this.ngxService.start();
 setTimeout(() => {
 this.ngxService.stop();
 }, 3000);
 if (newUser.email === "admin@gmail.com") {
 this.ngxService.start();
 this.authService.signIn().then(
 () => {
 console.log('Connexion réussite   !');
 this.authStatus = this.authService.isAuth;
 this.ngxService.stop();
 this.router.navigate(['espace-admin']);
 localStorage.setItem('token', "true");
 console.log(this.authStatus);
 }
 );
 localStorage.setItem('session', newUser.email);
 }else {
 this.ngxService.start();
 this.authService.signIn().then(
 () => {
 console.log('Connexion réussite   !');
 this.authStatus = this.authService.isAuth;
 this.ngxService.stop();
 this.router.navigate(['produits']);
 localStorage.setItem('token', "true");
 console.log(this.authStatus);
 }
 );
 //Parse the serialized data back into an aray of objects
 localStorage.setItem('session',newUser.email);
 }
 } else if (res === false){
 this.alertService.danger('Erreur de connexion! Vérifier vos données saisies');
 this.AuthForm.reset();
 }
 });
 }
 }