How can PHP be utilized to create a custom maintenance page that displays a message about the website being under construction?
To create a custom maintenance page using PHP, you can create a new PHP file (e.g., maintenance.php) with a message indicating that the website is under construction. Then, you can use PHP to redirect all traffic to this maintenance page by checking a flag or condition in your main index.php file. This way, visitors will see the maintenance message instead of the regular website content.
// maintenance.php
<!DOCTYPE html>
<html>
<head>
<title>Website Under Construction</title>
</head>
<body>
<h1>Sorry, this website is currently under construction. Please check back later.</h1>
</body>
</html>
// index.php
<?php
$underMaintenance = true; // Set this flag to true to enable maintenance mode
if ($underMaintenance) {
header('Location: maintenance.php');
exit();
}
// Normal website content goes here
?>