I am new to this part of communication between client site and server. My client is js who fetch object to php script called server.php.
registration.js
let json = {
name: name,
date: date,
phone: phone,
};
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(json),
};
fetch(
`http://localhost/php/server.php/registration`,
options
);
How do I know if request is a registration request or something else?
If i create in server.php script
if (isset($_POST'['registration']) { ... }
php says that is not set $_POST'['registration'];
$_POST contains data that is:
application/x-www-form-urlencoded or multipart/form-dataYour request body is encoded as application/json so $_POST will be blank, and registration appears in the URL, not the request body anyway.
Look to $_SERVER[PATH_INFO] instead.
Contains any client-provided pathname information trailing the actual script filename but preceding the query string, if available. For instance, if the current script was accessed via the URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain /some/stuff.