I am a beginner in PHP and web development. I need to create a simple website with sign-in and sign-up functionality for testing purposes. I have installed a LAMP server on a CentOS 8 virtual machine to run the website in my local environment. I have created the necessary PHP and HTML files, following the instructions provided in this tutorial here. Below are my coding files.
index.html
<!DOCTYPE html> <html> <head> <title>Demo Website</title> <style> body { margin-top: 50px; } h1 { text-align: center; } .sign-in-button, .sign-up-button { background-color: #000000; color: #ffffff; padding: 10px 20px; border-radius: 5px; margin: 5px; } .sign-in-button:hover, .sign-up-button:hover { background-color: #ffffff; color: #000000; } .sign-in-up-buttons { text-align: center; display: flex; justify-content: center; align-items: center; margin-top: 50px; } </style> </head> <body> <h1>Demo Website</h1> <div class="sign-in-up-buttons"> <a href="signin.html" class="sign-in-button">Sign in</a> <a href="signup.html" class="sign-up-button">Sign up</a> </div> </body> </html> signin.html
<!DOCTYPE html> <html> <head> <title>Applova Demo Website - Sign In</title> <style> body { margin-top: 50px; } h1 { text-align: center; } form { width: 500px; margin: 0 auto; } input { width: 100%; padding: 10px; margin-bottom: 10px; } button { background-color: #000000; color: #ffffff; padding: 10px 20px; border-radius: 5px; margin: 5px; } button:hover { background-color: #ffffff; color: #000000; } </style> </head> <body> <h1>Applova Demo Website - Sign In</h1> <form action="signin.php" method="post"> <input type="email" name="email" placeholder="Email address"> <input type="password" name="password" placeholder="Password"> <button type="submit">Sign in</button> </form> </body> </html> signin.php
<?php // Connect to the database $db = new PDO('mysql:host=localhost;dbname=users', 'root', 'root'); // Get the email address and password from the form $email = $_POST['email']; $password = $_POST['password']; // Validate the form data if (empty($email) || empty($password)) { echo 'Please enter your email address and password.'; die(); } // Check if the user account exists $user = $db->query('SELECT * FROM user_details WHERE email = ?', [$email])->fetch(); // If the user account exists, check the password if ($user) { if (password_verify($password, $user['password'])) { // Password is correct, log the user in session_start(); $_SESSION['user_id'] = $user['id']; header('Location: signon.html'); } else { // Password is incorrect echo 'Invalid email address or password.'; die(); } } else { // User account does not exist echo 'Invalid email address or password.'; die(); } ?> signon.html
<!DOCTYPE html> <html> <head> <title>Applova Demo Website - Logged in successfully</title> </head> <body> <h1>You are now logged in!</h1> <p>Welcome to the Applova Demo Website. You can now access all of the features of the website.</p> <a href="logout.php">Log out</a> </body> </html> sql dump:
-- phpMyAdmin SQL Dump -- version 4.7.9 -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1:3306 -- Generation Time: Jul 04, 2021 at 01:46 PM -- Server version: 5.7.21 -- PHP Version: 5.6.35 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `users` -- -- -------------------------------------------------------- -- -- Table structure for table `user_details` -- DROP TABLE IF EXISTS `user_details`; CREATE TABLE IF NOT EXISTS `user_details` ( `email` varchar(255) NOT NULL, `password` varchar(25) NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`email`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `user_details` -- INSERT INTO `user_details` (`email`, `password`, `name`) VALUES ('[email protected]', 'tom@123', 'tom'), ('damian@gmail', 'damian@123', 'damian'), ('jeff@gmail', 'jeff@123', 'jeff'); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; I am getting This page isn’t working192.168.1.129 is currently unable to handle this request. HTTP ERROR 500 error while sign in to website. What does cause this error?
Server HTTP service log:
[Fri Sep 22 00:13:17.126166 2023] [mpm_event:notice] [pid 1876847:tid 139940005054784] AH00492: caught SIGWINCH, shutting down gracefully [Fri Sep 22 00:13:19.556260 2023] [core:notice] [pid 1945191:tid 140346412464448] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0 [Fri Sep 22 00:13:19.562244 2023] [suexec:notice] [pid 1945191:tid 140346412464448] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Fri Sep 22 00:13:19.583880 2023] [so:warn] [pid 1945191:tid 140346412464448] AH01574: module wsgi_module is already loaded, skipping AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::934f:e559:2b39:da18. Set the 'ServerName' directive globally to suppress this message [Fri Sep 22 00:13:20.603289 2023] [lbmethod_heartbeat:notice] [pid 1945191:tid 140346412464448] AH02282: No slotmem from mod_heartmonitor [Fri Sep 22 00:13:20.605625 2023] [http2:warn] [pid 1945191:tid 140346412464448] AH02951: mod_ssl does not seem to be enabled [Fri Sep 22 00:13:20.610553 2023] [mpm_event:notice] [pid 1945191:tid 140346412464448] AH00489: Apache/2.4.37 (centos) mod_wsgi/4.7.1 Python/3.9 configured -- resuming normal operations [Fri Sep 22 00:13:20.610594 2023] [core:notice] [pid 1945191:tid 140346412464448] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
$db->query(). You have to call$db->prepare()to create the statement, and$stmt->query()to execute it with parameters.