Taruna Site — PHP

Build the Karang Taruna's PHP site on real PHP 8.4: forms, PDO, passwords, sessions and generators. 16 levels, right in the browser.

What you learn in this game

PHP runs on the server. The browser on a villager's phone never sees PHP code: only the result arrives, the HTML PHP printed. At the Karang Taruna's post, every choice you make becomes a PHP file run by the real PHP 8.4 with its built-in server, php -S. The log in the book copies what happened.

The fields of a form sent with method="post" reach PHP in the $_POST array, one key for each name. But not every field is always there.

In PHP, echo sends text as it is. The browser that receives it cannot tell which part is the page and which is a villager's name. Signs like <, " and & mean something in HTML.

PHP has two ways to compare. == converts types first when they differ, then compares. === converts nothing: type and value must both match. PHP 8 changed some of the old == rules, so old tutorials are sometimes wrong.

A function in PHP 8 can ask for a type for its parameters, int for example. When the value passed has another type, PHP tries to convert it first, unless the file asks for strict mode.

The function header() sends an HTTP header, Location for example, which tells the browser to go to another address. Its third argument is the response's status code. Each redirect code has its own rule for the method the browser uses next.