In this section of the website, I share practical code examples that help highlight the differences between common web development technologies and structures.
Each example is crafted to be clear, educational, and replicable, so anyone can understand the logic and experiment with the source code directly.
π Starting with a simple login database
I began with a basic login system using a user database and implemented it in three different ways:
- Basic login with plain PHP
Go to demo Β» - Login using RESTful API
Go to demo Β» - Login using JavaScript + AJAX
Go to demo Β»
π Code Snapshots & Key Differences
1. β Plain PHP (Basic)
The form sends the data directly to the PHP file that processes login and redirects:
<?php
require_once('../config/config.php');
$username = $_POST['username'] ?? '';
$password = md5($_POST['password'] ?? '');
$stmt = $pdo->prepare("SELECT * FROM utenti WHERE username = ? AND password = ?");
$stmt->execute([$username, $password]);
if ($stmt->fetch()) {
header("Location: welcome.php");
} else {
header("Location: error.php");
}
?>
- β Simple
- β Reloads the page
- β Not reusable for other apps
2. π REST API (PHP Endpoint)
Here the logic is separated into a clean backend API:
<?php
require_once('../config/config.php');
header('Content-Type: application/json');
$username = $_POST['username'] ?? '';
$password = md5($_POST['password'] ?? '');
$stmt = $pdo->prepare("SELECT * FROM utenti WHERE username = ? AND password = ?");
$stmt->execute([$username, $password]);
$user = $stmt->fetch();
echo json_encode(['success' => (bool) $user]);
?>
Frontend can use this with mobile apps or frontend frameworks.
- β Clean separation of logic
- β Reusable in other platforms
- β Requires understanding of APIs and response formats
3. π§ JavaScript + AJAX
Login is handled via fetch, without reloading the page:
fetch('check.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`
})
.then(res => res.json())
.then(data => {
if (data.success) {
window.location.href = 'welcome.html';
} else {
document.getElementById('message').textContent = 'Invalid credentials';
}
});
- β Modern and smooth UX
- β No full-page reload
- β Needs JS + server coordination
βοΈ Summary: Which one to choose?
| Goal | Best Option |
|---|---|
| Simplicity and speed | Plain PHP |
| API reuse or external apps | REST API |
| Smooth and modern user flow | JavaScript + AJAX |
In the next steps, I will cover more advanced topics like:
- Secure user registration
- Password reset flows
- Login using tokens (JWT)
- Full-stack integration examples
Do you want me to now convert this into an actual WordPress page layout using <div> and blocks, or leave it as raw text for your editor?
