Real-Time Domain Availability Checker in PHP (AJAX + WHOIS + DNS)
A modern PHP-based domain search tool with AJAX, DNS checks, and WHOIS fallback. Get instant domain availability results and smart suggestions in a fast, elegant UI.
Suggested:
Learn how to create a secure user registration and login system in PHP with MySQL. Step-by-step tutorial with code examples for beginners. Secure, simple, and easy to implement.
Creating a user registration and login system is a foundational task in many web applications. Whether you're building a blog, an e-commerce platform, or a custom dashboard, managing users securely is essential. In this tutorial, we'll walk through how to build a basic system using PHP and MySQL.
Table of contents [Show]
CREATE DATABASE user_system;
USE user_system;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Create a file named db.php for your database connection:
<?php
$host = 'localhost';
$db = 'user_system';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
?>Create register.php:
<form action="register.php" method="POST">
<h2>Register</h2>
<input type="text" name="username" placeholder="Username" required><br>
<input type="email" name="email" placeholder="Email" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button type="submit" name="register">Sign Up</button>
</form>And the PHP handling code:
<?php
require 'db.php';
if (isset($_POST['register'])) {
$username = htmlspecialchars($_POST['username']);
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
try {
$stmt->execute([$username, $email, $password]);
echo "Registration successful!";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>Create login.php:
<form action="login.php" method="POST">
<h2>Login</h2>
<input type="text" name="username" placeholder="Username" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button type="submit" name="login">Log In</button>
</form>And the login logic:
<?php
require 'db.php';
session_start();
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user'] = $user['username'];
echo "Login successful! Welcome, " . $_SESSION['user'];
// Redirect to dashboard or home page
} else {
echo "Invalid credentials!";
}
}
?>Protect pages like dashboard.php:
<?php
session_start();
if (!isset($_SESSION['user'])) {
header("Location: login.php");
exit();
}
echo "Welcome, " . $_SESSION['user'];
?>Create logout.php:
<?php
session_start();
session_unset();
session_destroy();
header("Location: login.php");
exit();
?>password_hash(), never store them in plain text.You’ve now built a working user registration and login system in PHP! This simple project lays the foundation for more advanced features like user roles, password reset, and secure sessions.
A modern PHP-based domain search tool with AJAX, DNS checks, and WHOIS fallback. Get instant domain availability results and smart suggestions in a fast, elegant UI.
Learn how to build an advanced AJAX contact form with PHP that sends email without page reload. Includes modern UI design, form validation, and secure email handling using PHP's mail() function.
Learn how to remove .php, .html, and .htm extensions from URLs using .htaccess. Create clean, SEO-friendly URLs on Apache servers with our step-by-step guide.