Login and registration form in php mvc

PHP MVC Register & Login

Login and registration form in php mvc

A simple PHP MVC user authentication application. I’ve used this as a starter framework for some of my own PHP applications. This would be useful for small projects. It will be advantageous if you know the basics of object-oriented programming and MVC and you are able to use the command line. This script is not for beginners.

License

Licensed under MIT. Totally free for private or commercial projects.

Requirements

  • PHP 5.5+
  • MySQL 5 database

Installation

  • Make sure you have Apache, PHP, MySQL installed.
  • Clone this repo to a folder on your server.
  • Activate mod_rewrite, route all traffic to application's www/public_html folder.
  • Edit config.php and set your database credentials.
  • Execute the SQL statements in the _install directory to setup database tables.

Install Composer

Go to project folder and run the composer install command;

Install Bower Components

Go to project folder and run the bower install command;

Install Database

Execute the SQL statements via phpmyadmin or the command line. In the following example "root", "password", "myApp" are the username, password and database name.

cat _install/db01-structure.sql | mysql --user=root --password=password myApp
cat _install/db02-constraints.sql | mysql --user=root --password=password myApp
cat _install/db03-inserts.sql | mysql --user=root --password=password myApp

Contents

  • 1 Step by Step Procedure to Create a Login Form in PHP
    • 1.1 MVC based a simple login form in PHP (Step by step tutorial)
      • 1.1.1 Step 1:
      • 1.1.2 Step 2:
      • 1.1.3 Step 3:
      • 1.1.4 Step 4:
      • 1.1.5 Step 5: 
      • 1.1.6  Step 6:
      • 1.1.7 Step 7:
    • 1.2 Fun Fact
    • 1.3 How can I create a website using php?

Step by Step Procedure to Create a Login Form in PHP

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

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

  • Getting Started. There are a few steps we need to take before we create our secure login system. …
  • Creating the Login Form Design. …
  • Creating the Database and setting-up Tables. …
  • Authenticating Users with PHP. …
  • Creating the Home Page. …
  • Creating the Profile Page. …
  • Creating the Logout Script.

First of all, let me explain the term MVC.

How to create admin login page using PHP?

  1. Create Database: Create a database using XAMPP, the database is named “loginpage” here. …
  2. Create Table: Create a table named “adminlogin”, inside “loginpage” database.
  3. Create Table Structure: The table “adminlogin” should contain three fields.

  • Models: (managing data) models usually store and retrieve data from DB.
  • Views: Representing data in the 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 a simple login form in PHP using MVC patterns.

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

Step 1:

Start a new PHP project

Login and registration form in php mvc
Create a new PHP project

name it as “form”

Login and registration form in php mvc

Note: Select the directory path as shown in the 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 a folder in your PHP project.

Login and registration form in php mvc

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

Login and registration form in php mvc

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

Login and registration form in php mvc

Step 3:

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

Login and registration form in php mvc

Step 4:

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

Login and registration form in php mvc

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 and registration form in php mvc
And write the following code in views/afterlogin.php file.

Login and registration form in php mvc

 Step 6:

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

Login and registration form in php mvc

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.

Login and registration form in php mvc


Disclaimer: This post is created as per my best knowledge until the time of creation. All the codes added in this post worked great for me but maybe there won’t work that way for you. So, hereby, I cannot guarantee that this tutorial will equally help you with your problem too. But I assure that this would be really helpful for students having a 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.

Fun Fact

How can I create a website using php?

To create a website using PHP, you’ll need to construct three web pages. These are based upon the basic structure of header, body, and footer. As you might guess, the header includes title information. However, information for the browser is also included, such as the HTML standard in use, along with CSS references.

Also See : YouTube playlist downloader – YouTube to mp3

How to combine multiple filters on Snapchat pictures easily?

Salma Noreenhttp://www.salmanoreen.com/

I am Salma Noreen from Attock, Pakistan. After completing MBA Finance & Marketing, I continued towards MIT, so I’m have not only expertise and skills in IT but also in Accounts and Marketing. I am enough of an artist to draw freely upon my imagination. I am neither especially clever nor especially gifted. I am only very, very curious. The Curiosity about learning new technologies, is gifted, I believe. I have always followed my curiosity, and I always do what I love to do, and that’s the reason behind my success in field of Web Application Programming, Internet Marketing, Security Enhancement, and SEO Consultancy.