ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

PHP Tutorial• 6 min read

PHP Introduction & The Request-Response Cycle

How server-side scripting powers over 75% of the web

PHP (Hypertext Preprocessor) is an open-source, server-side scripting language executed on the web server before the resulting HTML is delivered to the client browser.

Client-Side vs Server-Side Execution

When a user requests a PHP webpage, the web server (Apache, NGINX, or PHP built-in server) intercepts the request, runs the PHP interpreter, and returns pure static HTML/JSON to the browser.

The client never sees raw PHP source code, passwords, or database credentials—only the generated output.

PHP code blocks are enclosed in <?php ... ?> tags and can be embedded directly within HTML markup.

Your First PHP Script (index.php)
<?php
  // Server-side timestamp and dynamic greeting
  $appName = "Codexia Web Academy";
  $serverYear = date("Y");
  $isLive = true;

  echo "<h1>Welcome to " . $appName . "</h1>";
  echo "<p>Server copyright year: " . $serverYear . "</p>";
?>
The echo statement sends text to the browser. Periods (.) are used for string concatenation.
Pro Tip

If your file contains exclusively PHP code, it is best practice to omit the closing ?> tag to avoid accidental whitespace issues in HTTP headers.

ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Where is PHP code executed when a user requests a web page?