PHP - Hypertext Preprocessor
PHP - Hypertext Preprocessor
PHP = Hypertext Preprocessor 🌀
It's a server-side scripting language ⚙️ used mainly for web development 🌍📱
🧠 Generate dynamic web pages 📄➡️⚡
💬 Handle forms 📝✉️
🗄️ Connect to databases (like MySQL 🐬)
🧑💻 Manage user sessions 👥🔐
📦 Build full websites and applications 🏗️🌐
php
<?php
echo "Hello, World! 🌎✨";
?>
🚀 Fast to learn & use
💻 Works on many platforms (Linux 🐧, Windows 🪟, macOS 🍎)
🔌 Integrates easily with HTML 🧱
📚 Huge community + tons of libraries 🧰🧠
💰 Powers big websites like WordPress 📰, Facebook (originally) 🌐
🛒 E-commerce sites
📇 Contact forms
🧾 Blogs & content management (CMS like WordPress 📝)
🛠️ Admin panels
📦 APIs and backends
PHP is your friendly neighborhood 🕸️ web development superhero 🦸♂️ that helps create dynamic, interactive, and data-driven websites 🌟⚙️🎯
Author: Rasmus Lerdorf 🇩🇰
PHP began as a simple set of CGI scripts called "Personal Home Page Tools" 🔧🖼️
Purpose: Track visitors on Lerdorf's personal website 📊
Early version = raw and not very flexible 🧱
Renamed to "PHP/FI" (Forms Interpreter) ✍️
Got basic support for forms, HTML embedding, and database connections 📝🔗
Started gaining popularity in developer communities 👨👩👧👦
Major overhaul by Zeev Suraski and Andi Gutmans 🧑💻👨💻
Introduced a modular architecture 🧩
Supported more databases, protocols, and platforms 🔗🌐
Officially renamed PHP: Hypertext Preprocessor ♻️
Introduced the Zend Engine 1.0 (the core engine) 🧠🔥
Better performance, session handling, and output buffering 🚴♂️💨
Widely adopted across the web 💼💻
Major leap with Object-Oriented Programming (OOP) 🧱👑
Better error handling (try/catch) 🚨🛠️
PDO (PHP Data Objects) added for secure DB access 🔒📊
Real enterprise adoption began 🌍💼
Huge performance jump (2x faster than PHP 5.6) 🚀
Scalar type declarations 🧮
Return type declarations ✅
Null coalescing operator (??) 🙃
Killed off PHP 6 (which was planned but never officially released) 🪦💀
Introduced the JIT compiler (Just-In-Time) 🏎️
Named arguments, union types, attributes (annotations) 🧩
Match expressions (switch on steroids) ⚖️
Cleaner, faster, smarter syntax and tools 🧼⚙️💥
Enums 🏷️
Fibers (for async tasks) ⚡
Readonly properties 🔐
Performance tuning & security tightening 🔐📏
Still one of the most-used languages in web development 🌐
Powers over 75% of websites (including Facebook’s early versions and WordPress) 🧱🏛️
Modern PHP is fast, secure, and feature-rich 🚀🔒💎
Community-driven and constantly evolving 🤝🌱
“From a simple home project to a global web-building giant, PHP’s journey is a testament to community power and persistent evolution.” 🌟👨💻🌎
This is the simplest and most common beginner use of PHP: displaying a message in the browser.
php
<!DOCTYPE html>
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<h1><?php echo "Hello, World! 🌍"; ?></h1>
</body>
</html>
The browser loads the HTML page 📄
When it sees <?php echo ... ?>, the PHP engine runs the code on the server
It sends back a completed HTML page with "Hello, World! 🌍" in it
Save it as index.php
Put it in the htdocs folder if using XAMPP, or www in WAMP/LAMP
Start your local server
Visit http://localhost/index.php in your browser
Scenario: A user enters their name in a form. PHP greets them. 😊
form.html
html
<form action="form_handler.php" method="post">
Enter your name: <input type="text" name="username">
<input type="submit" value="Submit">
</form>
form_handler.php
php
<?php
$name = $_POST['username'];
echo "Hello, " . htmlspecialchars($name) . "! 👋";
?>
$_POST = retrieves data from the form
htmlspecialchars() = prevents HTML injection (basic security)
Server processes input and returns dynamic content
🔐 Login/authentication systems
📊 Database connections (MySQL with PDO or MySQLi)
📤 File uploads and downloads
📧 Sending emails via PHP mail() function
🧠 RESTful APIs using frameworks (like Laravel, Symfony)
Install XAMPP
Run APACHE and MySQL
c:\xampp\htdocs put a test.php file with the code
<?php
echo "PHP is working";
?>
In browser run
http://localhost/test.php
Open a notepad - type the following
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Login Form</h2>
<form action="login.php" method="post">
Username: <input type="text" name="username"><br><br>
Password: <input type="password" and name="password"><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
Explained: -
<head>
<title>Login</title>
</head>
this above does not come on the screen, it is for the backend
<h2>Login Form</h2>
Displays a large heading:
➤ Login Form is just the title you see on the page.
<form action="login.php" method="post">
This starts a form element.
action="login.php":
➤ When the user clicks the Login button, the form data is sent to the login.php file to be processed.
method="post":
➤ It tells the browser to send the form data securely in the background, not in the URL (better for passwords).
Username: <input type="text" name="username">
This creates a text input field for the username.
name="username":
➤ This is the key that PHP uses to read the value.
➤ In login.php, you access it using $_POST['username'].
html
Copy code
Password: <input type="password" name="password">
This creates a password input field — characters are hidden as you type.
name="password":
➤ Used in PHP as $_POST['password'].
html
Copy code
<input type="submit" value="Login">
This is the submit button.
When clicked, it sends all form data (username + password) to login.php using the POST method.
<?php
$correct_username = "admin";
$correct_password = "1234";
$username = $_POST['username'];
$password = $_POST['password'];
if ($username === $correct_username && $password === $correct_password) {
echo "✅ Login successful! Welcome, $username.";
} else {
echo "❌ Invalid username or password.";
}
?>
You now have two separate files:
This file shows the form to the user, like this:
<form action="login.php" method="post">
This line says:
👉 “When the user submits the form, send the data to login.php.”
This file receives the data that the user typed (username and password), and checks it with PHP.
So the flow is:
User opens http://localhost/loginform.php
They enter username & password, and click Login
The browser sends the form data to:
http://localhost/login.php
PHP in login.php checks the credentials and shows the result.
In real websites, it's exactly like this:
One page shows the form (HTML)
Another page handles the logic (PHP, or JavaScript in some cases)
You can also combine both in one file, but keeping them separate is easier to understand as you're learning.
✅ So yes, both files are needed, and they match through this line:
<form action="login.php" method="post">
This is how your form "talks" to the PHP processor.