login form HTML codes
Facebooktwitterpinterestlinkedin

You must be landed here to complete your basic assignment of creating a simple login form in PHP (MVC based).

MVC might be new term for you if you are learning PHP now a days. Well, it is Model View Controller (MVC) patterns. Such patterns make programming simple and easier.

First of all, let me explain the term MVC.

  • Models: (managing data) models usually store and retrieve data from db.
  • Views: Representing data in requested format. Layout/styling etc.
  • Controllers: Handling the Models and Views. Controllers fetch the requests from the clients ==> forward to Models for requested operations ==> Finally displaying required output from views.

MVC based a simple login form in php (Step by step tutorial)

Now, let’s move ahead for creating simple login form in php using MVC patterns.

Note: I am using eclipse text editor on Mac so don’t get confuse in screenshots.

Step 1:

Start a new PHP project

Create a new PHP project
Create a new PHP project

 

name it as “form”

Name it as form for creating MVC based a simple login form

 

Note: Select the directory path as shown in above screenshot if it isn’t set as default.

/Applications/XAMPP/xamppfiles/htdocs/form

Step 2:

Create 3 folders in your PHP project and a single PHP file “index.php”

Follow the screenshots.

Screen #1: creating folder in your PHP project.

How to create a folder in eclipse text editor

Screen #2: Creating a PHP file in eclipse TextEditor.

Creating a PHP file in eclipse texteditor

So, three folders and a PHP file are ready to work on?

MVC - Models Views Controllers and index file

 

Step 3:

In “controllers” folder, create a new PHP file with the name controller.php and insert the following code.

In controllers folder, create a new PHP file with the name controller.php and copy & paste the following code.

Step 4:

In “models” folder, create a new PHP file with the name models.php and insert the following code.

In "models" folder, create a new PHP file with the name models.php and insert the following code

Step 5: 

Create two new PHP files in the “views” folder, with the names login.php and afterlogin.php

Write the following code in views/login.php

login form HTML codesAnd write the following code in views/afterlogin.php file.

views / after login code

 

 Step 6:

Finally, open the index.php and insert following code.

index page code for creating a simple login form

Step 7:

Test your code into your browser such as localhost/form. It was a simple login form but you can add CSS to style it further.

A Simple Login Form


Disclaimer: This post is created as per my best knowledge till the time of creation. All the codes added in this post worked great for me but maybe these won’t work that way for you. So, hereby, I cannot guarantee that this tutorial will be equally help you in your problem too. But I assure that this would be really helpful for students having basic knowledge of php and looking for creating very basic php login form.

Well, if you think anything in this post wasn’t appropriate and should be removed, please let me know in comments below.

 

Facebooktwitterpinterestlinkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Close