Login with Session using PHP/MySQLi in Angular JS

To create a login page using Angular JS and set SESSION with PHP/MySQLi. Angular JS is a javascript framework maintained by Google and is capable of creating Single-Page Applications. In this tutorial, we’ll set up PHP Session to prevent users from going into our homepage if not authenticated.

Getting Started

I’ve have used CDN for following :

  • Boostrap
  • Angular JS
  • Angular Route

Used CDN’s for the plugins/libraries/frameworks, this means you will be needing an internet connection in order to work the scripts below properly.

Creating our Database

First, we are going to create our database and insert sample users to test our app.

  1. Open phpMyAdmin.
  2. Click databases, create a database and name it as angular.
  3. After creating a database, click the SQL and paste the below codes. See the image below for detailed instruction.
You can then use the ff login details:

Username: neovic
Password: devierte

Username: gemalyn
Password: cepe

Username: julyn
Password: divinagracia

Index.html

html

 

Login.html

html

 

Home.html

 

Angular.js

JavaScript

 

LoginCtrl.js

This contains  angular controller for login.html.

 

HomeCtrl.js

Angular controller for home.html.

 

LoginService.js

Angular service for our login.

 

SessionService.js

Angular service that handles our session.

Login.php

This is our PHP code for login.

php

Session.php

PHP code is checking if the session has been set.

Fetch.php

PHP code in fetching the details of the logged-in user.

 

Logout.php

Lastly, this PHP code in destroying our current PHP Session.

 

Download Code Angular Login with Session

Leave a Comment

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

Scroll to Top