PHP is a server-side scripting language used to create dynamic and interactive web pages. It runs on the web server and sends processed output (HTML) to the browser.
👉 Draw this in exam:
Browser → Request → Web Server (PHP Code)
↓
Process Logic
↓
Send HTML Response → Browser
✔ PHP code is executed on server, not visible to user.
<?php
echo "Hello World";
?>
<?php and ends with ?>;echo is used to display outputVariables store data values.
<?php
$name = "Ali";
$age = 20;
?>
$+ - * / %=== != > <&& || !<?php
$x = 10 + 5;
?>
<?php
if ($x > 10) {
echo "Greater";
} else {
echo "Smaller";
}
?>
<?php
for ($i = 0; $i < 5; $i++) {
echo $i;
}
?>
<?php
function greet() {
echo "Hello!";
}
greet();
?>
<form method="post">
Name: <input type="text" name="name">
<input type="submit">
</form>
<?php
$name = $_POST['name'];
echo $name;
?>
<?php
$conn = mysqli_connect("localhost", "root", "", "test");
?>
$_GET$_POST$_SERVER$_SESSION$_COOKIE<?php
session_start();
$_SESSION["user"] = "Ali";
?>
<?php
setcookie("user", "Ali", time()+3600);
?>
User Request → Server → PHP Execution → Database → Response (HTML)
✔ PHP runs on server-side
✔ File extension is .php
✔ Can be embedded in HTML
✔ Use $_POST for secure data transfer
✔ Always validate user input
PHP = Server-side language
Used for:
Key features:
$)👉 Works with HTML + CSS + JavaScript to build full web applications.
Open this section to load past papers