Country-Click is a lightweight, stateless PHP web application with no database, no sessions, and no caching layer. Every page load either shows the world map with no country selected, or re-fetches country data live from the REST Countries API based on POST input received from either the search bar or the SVG map click handler. Because there is no persistent state, the application is entirely self-contained in a small set of PHP files and a single JavaScript file.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AndresLopezCorrales/Countries-WebPage/llms.txt
Use this file to discover all available pages before exploring further.
Request lifecycle
User visits index.php
PHP immediately includes
controller/ApiConsumer.php and instantiates an ApiConsumer object. The page then renders the navbar (with the search form), the inline SVG world map, and calls $consumer->menu() to render the country info panel. On a fresh load with no POST data, menu() exits early and nothing is displayed in the panel.User clicks a country or submits the search form
Clicking a country on the SVG map triggers the JavaScript click handler in
resources/js/getname.js, which dynamically creates a hidden form and POSTs the xlink:title attribute of the clicked element as the field titulo back to index.php. Submitting the search form POSTs the typed text as the field search (along with the submit button name) to the same index.php.ApiConsumer reads the POST data
ApiConsumer::searchBar() checks for $_POST['submit'] and $_POST['search']. If the search bar was used, it returns the typed text. If the map was clicked, GetNameController::clickCountries() checks for $_POST['titulo'] and returns the country title from the SVG element.ApiConsumer::getSearchBarInfo() builds the API URL and calls file_get_contents()
The country name is URL-encoded (spaces replaced with
%20) and appended to the REST Countries API base URL: https://restcountries.com/v3.1/name/{name}. The request is made with file_get_contents() using a custom stream context that sets ignore_errors: true, ensuring HTTP error bodies (like 404 responses) are returned as readable strings rather than triggering a PHP warning.The JSON response is decoded and passed to GetAttributesController methods
The raw response string is decoded with
json_decode($response, true). If the result does not contain an error status, each field is extracted by a dedicated method on GetAttributesController: getCommonName(), getOfficialName(), getRegion(), getPopulation(), getCapital(), getLanguage(), getTimezone(), and getFlag(). The language array is then joined into a comma-separated string with implode().ApiConsumer::menu() renders the country info HTML panel
All eight extracted values are assembled into the
$allAttributes array and returned from getSearchBarInfo(). Back in menu(), each value is unpacked by index and embedded directly into an echo’d HTML string that displays the country name, official name, flag image, capital, population, languages, timezone, and a region continent image.Component diagram
Stateless design
Because there is no session, database, or cache, every request is entirely self-contained. The PHP process receives a POST (or a plain GET on fresh load), optionally fetches from the REST Countries API, renders the full HTML page, and terminates. Nothing persists between requests. This design makes deployment trivial — the application runs on any standard PHP web host with no configuration beyond uploading the files. There are no migrations, no environment-specific setup, and no background workers. The trade-off is that every search or map click results in a live outbound HTTP request torestcountries.com. If the API is unavailable or slow, the user will experience a delay or an error message. Responses are never cached, so repeated lookups for the same country always incur a fresh API call.
Input priority
WithingetSearchBarInfo(), the search bar takes priority over the map click. If searchBar() returns a non-empty string, that value is used as the country name. Only when searchBar() returns an empty string does the method fall back to GetNameController::clickCountries() to read the map click value. This ensures that if a user somehow triggers both inputs simultaneously, the typed search text always wins.
ApiConsumer.php
The app uses PHP’s
file_get_contents() with stream_context_create(['http' => ['ignore_errors' => true]]) so HTTP error responses (like 404) are returned as body text rather than triggering a PHP warning. This allows the application to read the JSON error payload from the REST Countries API and display a user-friendly message instead of a fatal PHP error.