Ask the server who it is
The simplest possible conversation: the frontend asks, the backend answers.
Sends a GET request to /api/hello.php
The answer will appear here.
Show me the code on both sides
π₯οΈ Frontend app.js β in your browser
// Ask, then wait for the answer to come back.
const res = await fetch('/api/hello.php');
const data = await res.json();
show(data.php_version, data.hostname);
βοΈ Backend api/hello.php β on the server
<?php
// Facts only this machine knows.
send([
'php_version' => PHP_VERSION,
'hostname' => php_uname('n'),
'server_time' => date('c'),
]);