Php Script for Login Page
Our PHP script is prepared to make you best design login page and other control panels. If you want to easily manage your users, this script is the right choice for you. We also provide Resell Rights login panel. It means that you can use our products on commercial purpose without paying any hosting fees or do not have to send your clients to us in order they could download our products. All the customers who come to your site will be able to make positive comments about your business ethics and good taste.
A lightweight and easy to use login page for your website. Either integrate with an existing database, or link to one via cgi/php. No database knowledge required. Page has a scrolling header, with some javascript code included to simulate hovering over words in the title bar. Content includes simple login form, and a “forgot password” form. Example code is also provided to set up a php handling page – so you can link directly to the php page which will present the login page.
Create a HTML PHP Login Form
To create a login form, follow the steps mentioned below:
- Open Microsoft Visual Studio -> create a new file and name it as an SL file
- Now, on a page, write the code mentioned in the example below
- The HTML program will create a webpage form that will allow users to log in themselves
The code consists of HTML elements. The basic elements are:
<title>
The element displays the heading of the document. The label can be only in the text format, and it shows the text in the browser’s tab.
<link>
It creates a link between the working document and an external resource.
<form>
The element defines the user input included while creating an HTML.
<input type>
It displays a one-line input field.
<label>
It defines a label for many form elements. It majorly indicates the radio button/checkbox.
<!DOCTYPE html>
<html>
<head>
<title>LOGIN</title>
<link rel=”stylesheet” type=”text/css” href=”style.css”>
</head>
<body>
<form action=”login.php” method=”post”>
<h2>LOGIN</h2>
<?php if (isset($_GET[‘error’])) { ?>
<p class=”error”><?php echo $_GET[‘error’]; ?></p>
<?php } ?>
<label>User Name</label>
<input type=”text” name=”uname” placeholder=”User Name”><br>
<label>Password</label>
<input type=”password” name=”password” placeholder=”Password”><br>
<button type=”submit”>Login</button>
</form>
</body>
</html>
PHP MySQL Login System
In this topic, we will learn how to create a PHP MySQL Login System with the help of PHP and MySQL database. There are few steps given for creating a login system with MySQL database.
Before creating the login system first, we need to know about the pre-requisites to create the login module.
Requirements
- We should have knowledge of HTML, CSS, PHP and MySQL for creating the login system.
- Text Editor – For writing the code. We can use any text editor such as Notepad, Notepad++, Dreamweaver, etc.
- XAMPP – XAMPP is a cross-platform software, which stands for Cross-platform(X) Apache server (A), MySQL (M), PHP (P), Perl (P). XAMPP is a complete software package, so, we don’t need to install all these separately.
Environment Setup
Now, we need to start the webserver and create the files for the login system. There are few steps that are given below to setup the environment.
- Open the XAMPP Control Panel.
- Start the Apache server by clicking on the Start button.
- Start the MySQL by clicking on the Start button.
- Create all the files needed for login.
- Create login table in the database using phpMyAdmin in XAMPP.
Code the User Registration
It’s finally time to implement the registration functionality. The main function of this code is to check if the supplied email is already registered. If it’s not, we enter the username, email, and password into the database.
Place the following code at the top of registration.php.
01020304050607080910111213141516171819202122232425262728 | <?php session_start(); include ( 'config.php' ); if (isset( $_POST [ 'register' ])) { $username = $_POST [ 'username' ]; $email = $_POST [ 'email' ]; $password = $_POST [ 'password' ]; $password_hash = password_hash( $password , PASSWORD_BCRYPT); $query = $connection ->prepare( "SELECT * FROM users WHERE email=:email" ); $query ->bindParam( "email" , $email , PDO::PARAM_STR); $query ->execute(); if ( $query ->rowCount() > 0) { echo '<p class="error">The email address is already registered!</p>' ; } if ( $query ->rowCount() == 0) { $query = $connection ->prepare( "INSERT INTO users(username,password,email) VALUES (:username,:password_hash,:email)" ); $query ->bindParam( "username" , $username , PDO::PARAM_STR); $query ->bindParam( "password_hash" , $password_hash , PDO::PARAM_STR); $query ->bindParam( "email" , $email , PDO::PARAM_STR); $result = $query ->execute(); if ( $result ) { echo '<p class="success">Your registration was successful!</p>' ; } else { echo '<p class="error">Something went wrong!</p>' ; } } } ?> |
The first step is to include config.php and start the session. This helps us store any information that we want to preserve across the pages.
Next, we check if the user has clicked on the Register button to submit the form by checking if $_POST['register']
has been set. Always remember that it isn’t a good idea to store passwords as plain text. For this reason, we use the password_hash() function and then store that hash in our database. This particular function creates a 60-character hash using a randomly generated salt.
Finally, we execute the query and check if a non-zero row number exists for a given email address. If it does, the user will get a message saying the email address is already registered.
If no row exists with the given email address, we enter the supplied information into our database and let the users know that the registration was successful.
Create a CSS Code for Website Design
Next comes the CSS sheet. Now, the aim is to create a cascading style sheet (CSS) file to improve the design of the webpage.
The code for the .css file is below:
body {
background: #91a716;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-direction: column;
}
*{
font-family: cursive;
box-sizing: padding-box;
}
form {
width: 1000px;
border: 3px solid rgb(177, 142, 142);
padding: 20px;
background: rgb(85, 54, 54);
border-radius: 20px;
}
h2 {
text-align: center;
margin-bottom: 40px;
}
input {
display: block;
border: 2px solid #ccc;
width: 95%;
padding: 10px;
margin: 10px auto;
border-radius: 5px;
}
label {
color: #888;
font-size: 18px;
padding: 10px;
}
button {
float: right;
background: rgb(35, 174, 202);
padding: 10px 15px;
color: #fff;
border-radius: 5px;
margin-right: 10px;
border: none;
}
button:hover{
opacity: .10;
}
.error {
background: #F2DEDE;
color: #0c0101;
padding: 10px;
width: 95%;
border-radius: 5px;
margin: 20px auto;
}
h1 {
text-align: center;
color: rgb(134, 3, 3);
}
a {
float: right;
background: rgb(183, 225, 233);
padding: 10px 15px;
color: #fff;
border-radius: 10px;
margin-right: 10px;
border: none;
text-decoration: none;
}
a:hover{
opacity: .7;
}
Save the file name as “Style.css” in Microsoft Visual Studio.
The output for the code looks like following:

When the user submits the input values, they will be verified against the credentials stored in the database. Here, if the username and password are matched, the user will be taken to the next webpage. Otherwise, the login attempt will be rejected.
Now, to log in, it is important to add the credentials to the database.
Conclusion
Script is helpful when you are making a new login page with PHP, It gives 6 secure method to validate the user. The script allows you to set the preferences in the database. It is based on username, email and password. If a user attempts to gain access using a username that has already been registered, an error message is displayed and the login process fails to prevent further access by unauthorized users.