Skip to content

PHP Tutorial Getting Started with PHP

Server-Side vs Client-Side Code

Lesson 5 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

Code can run in two places. Client-side code runs on the visitor’s device, inside the browser. Server-side code runs on the computer that hosts the website.

Client-sideServer-side
ExamplesHTML, CSS, JavaScriptPHP, Python, Node.js
Runs onThe visitor’s browserThe web server
Can the visitor read the code?Yes, alwaysNo, only the output
Can it reach the database?Not directlyYes
Speed of reactionInstant, no networkNeeds a request

The trust rule

Everything that runs in the browser can be changed by the visitor. A person can open the developer tools, edit the page, turn off JavaScript or send a request by hand without using your form at all.

That leads to a rule you will use throughout this course:

Never trust data that comes from the browser. Always check it again in PHP.

index.php
PHP
<?php
// The browser sent this price. A visitor could have changed it.
$priceFromBrowser = "1";

// The real price comes from your own data.
$realPrice = 49.99;

echo "Charging: " . $realPrice;
Output
OUTPUT
Charging: 49.99

The shop charges the price it knows, not the one the browser sent.

Which side for which job

  • Server-side: passwords, payments, permissions, saving data, anything secret.
  • Client-side: quick feedback, animations, menus, anything that should react without a page reload.
lightbulb
Use both for forms
Check a form in JavaScript so the user gets a fast message, then check it again in PHP so bad data can never get in. Form Validation shows the PHP side.