docs / articles / Simple Login Example

Simple Login Example

Sara Jul 09, 2026 2026-07-09 04:40:45

In today's digital age, secure and simple login processes are crucial for user-friendly websites and applications. A simple login example can help us understand the basics of user authentication, a fundamental aspect of web development. Let's delve into a straightforward login example using HTML, CSS, and JavaScript, along with PHP for server-side processing.

Clean Login UI Design in Figma
Clean Login UI Design in Figma

Before we dive into the code, let's understand the basic flow of a login process. It typically involves three steps: user input (username and password), form submission, and server-side validation. If the credentials are valid, the user is redirected to the dashboard; otherwise, an error message is displayed.

Sign Up Webpage Design
Sign Up Webpage Design

Setting Up the Login Form

The first step is to create a simple HTML form for user input. We'll keep it minimal, asking only for a username and password.

two mobile phone screens with the words hello and sign up
two mobile phone screens with the words hello and sign up

Here's a basic example:

```html



```

HTML Form Structure

Webflow Login Form With Google Auth for Webflow
Webflow Login Form With Google Auth for Webflow

The form has an action attribute that points to the server-side script ('login.php') that will process the form data. The method attribute is set to 'post', which means the form data will be sent to the server in the body of the HTTP request.

The form includes two input fields for the username and password, both marked as required. A submit button is also included to send the form data to the server.

Styling the Form with CSS

Simple Login Screen || Mobile Application Login Screen || Mobile Application Login
Simple Login Screen || Mobile Application Login Screen || Mobile Application Login

To make the form more appealing, we can add some basic CSS styling. Here's an example:

```css form { width: 300px; margin: auto; } label, input { display: block; margin-bottom: 10px; } input[type="submit"] { background-color: #4CAF50; color: white; cursor: pointer; } ```

Processing the Login Form with PHP

Now, let's create the 'login.php' file that will process the form data. For this example, we'll use a simple array to store some dummy user credentials. In a real-world application, you would use a database to store user information.

Sign in & Sign up in one page with Luxury Design
Sign in & Sign up in one page with Luxury Design

Here's a basic PHP script that demonstrates form processing:

```php 'password123', 'john' => 'secret', 'jane' => 'qwerty', ]; $username = $_POST['username'] ?? ''; $password = $_POST['password'] ?? ''; if (isset($users[$username]) && $users[$username] === $password) { header("Location: dashboard.php"); exit; } else { header("Location: index.php?error=1"); exit; } ?> ```

PHP Form Processing

info ali sahab
info ali sahab
Login page ui design
Login page ui design
the gratify login screen is shown in this screenshote image, it appears to be dark blue
the gratify login screen is shown in this screenshote image, it appears to be dark blue
Icons for social media logins
Icons for social media logins
Login page through HTML and CSS
Login page through HTML and CSS
Modern Login Screen UI/UX
Modern Login Screen UI/UX
Modern Login & Sign Up UI/UX Design for Mobile Apps | Clean App Interface Ideas
Modern Login & Sign Up UI/UX Design for Mobile Apps | Clean App Interface Ideas
a green and white web page with the words welcome on it's front cover
a green and white web page with the words welcome on it's front cover
Top 10 Mobile Login Screen Designs for UI/UX Inspiration 📱✨
Top 10 Mobile Login Screen Designs for UI/UX Inspiration 📱✨
the welcome sign in screen is displayed on a purple background
the welcome sign in screen is displayed on a purple background
a green login form on a computer screen
a green login form on a computer screen
Dailyui day 01 - Login page
Dailyui day 01 - Login page
the login screen on an iphone, with two different buttons and one button highlighted
the login screen on an iphone, with two different buttons and one button highlighted
How To Make A Website With Login And Register | HTML CSS & Javascript
How To Make A Website With Login And Register | HTML CSS & Javascript
an image of a login screen with the words'create new account'on it
an image of a login screen with the words'create new account'on it
the login form is open and there is a man entering it with his hand on the door
the login form is open and there is a man entering it with his hand on the door
Premium Login Page UI Design | Modern Web Interface
Premium Login Page UI Design | Modern Web Interface
a white and black login page on a computer
a white and black login page on a computer
Login page UI design
Login page UI design
Html CSS Responsive Form Design With Full Code Free Template
Html CSS Responsive Form Design With Full Code Free Template

The PHP script first defines an array of user credentials. It then retrieves the username and password from the form data using the $_POST superglobal. The '??' operator is used to provide a default value if the key is not set.

Next, the script checks if the provided username exists in the array and if the provided password matches the stored password. If the credentials are valid, the user is redirected to the dashboard using the 'header()' function. If not, the user is redirected back to the login form with an error parameter in the query string.

Displaying Error Messages

To display an error message when the login attempt fails, we can add a check for the 'error' parameter in the query string and display an error message if it's present.

```html

Invalid username or password.

```

In a real-world application, you would also want to hash and salt passwords for security reasons. However, this is beyond the scope of this simple login example.

In conclusion, creating a simple login example involves setting up an HTML form, styling it with CSS, and processing the form data with PHP. This example demonstrates the basic flow of user authentication, but it's important to remember that in a real-world application, you would need to implement additional security measures and use a database to store user information.