I'm working on login authentication and having trouble identifying the failure. Via AJAX I pass the username and password to login.php which calls a PHP REST API to verify credentials and respond with a JSON containing the account status and a message that gets pushed back up to the UI.
I'm calling the api using file_get_contents. The apiURL is localhost/api/v1/login.
login.php
$data = array('username' => $username, 'password' => $password);
    $options = ["http" =>
        ["method" => "POST",
            "header" => "Content-Type: application/json",
            "content" => json_encode($data)
            ]
        ];
    // Call API
    $apiResponse = json_decode(file_get_contents($apiUrl, NULL, stream_context_create($options)));
The problem seems to be my api call, but I cannot figure out what the issue is.
API
$response = array("status" => "active", "message" => "success");
            header('Content-Type: application/json');
            echo json_encode($response);
I test my API using the postman chrome extension and send and receive JSON without issue so the API code is working. If I do a var_dump($apiResponse) in login.php I get NULL as the value returned from the API.
Any thoughts on why this value is NULL? Am I calling the api endpoint incorrectly?
 
     
     
    