I am new to PHP, I would like to develop a simple API in php that is to print out the login name and password in the page of the API php:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Access-Control-Allow-Methods: GET, POST");
$eData = file_get_contents("php://input");
$dData = json_decode($eData, true);
$staff = $dData['staff'];
$pass = $dData['pass'];
echo json_encode($staff);
echo json_encode($pass);
However, error messages are shown in the browser:
Warning: Trying to access array offset on value of type null
I have tried to run the program by inputting some text (e.g. I enter “Peter” in the field of login Name, and I enter “12345” in the field of password, I can see both the login name and password are found in the response of the network. Therefore, it seems that the API connection works, but why I can’t print out the code in the php? And how I can do that?