How to build a web app with minimal resources

How to build a web app with minimal resources

Before you study how to build a web app, you must imagine the result. Before you start coding you must set the goals, imagine the whole project and decide what the folders structure will be, and which files you will need. In this case, the goal is very easy: to build your first web on PHP with the possibility of users registration, login, and logout, and with the possibility of making users changes.

The structure of Files and Folders

If you wonder how to build a web application you must know that OOP PHP programming uses classes and objects to do necessary application operations. For our project, we will create 3 classes. The first class is User (will contain information about the user with a simple save function save()), the second one is UserTools (will contain functions that users need, such as login(), logout() and others…), the third one is a database class (it will serve as a liaison – connecting to the database, making changes, inserting new rows, and more).

In addition to the classes, we will also use a file called global.inc.php. This file will be called from each page and perform common operations that we need. For example, in this file, we will implement a DB connection on the each page.
The other files are needed for user pages: index.php, register.php, login.php, logout.php, settings.php and welcome.php.

Here is how the basic structure will look like:

how to create a web app

Creating the Database and users table

Your server should have MySQL installed. First, we need to create a new database for your application. In this database, create a users table. The following SQL code can be used:

Primary key acts as the “id” and this is what we will use to identify our users.
We will also have a unique field  – a “username”. Other required fields are “password”, “email”, “join_date”.

Creating  a DB.class.php class

The aim of this class is very simple: to reduce the use of SQL for accessing the database as much as possible and arrange the data in a convenient format.

Here is the code:

Class User (User.class.php)

This class will identify each user. With the growth of this application the definition of “User” can vary significantly. Fortunately, OOP programming makes it easy to add additional user attributes.

Constructor

In this class we will use a constructor – it is a function which is automatically called when you create another copy of the class. This allows us to automatically publish some attributes after you create the project. In this class, the constructor will take a single argument: an associative array containing a row from the users table of our DB.

The code is below:

Save information about users in the database

Save function is used to make changes to the database table with the current values in the User object. Using class variables, set the array $data. If the user’s data is saved for the first time, then $isNewUser is passed as $true (default is false).

Class UserTools.class.php

This class will contain functions that are related to users: login(), logout(), checkUsernameExists() and get(). But with the extension of this application, you can add many others.

Here is the code:

The final backend touch: global.inc.php

global.inc.php  is required for each page. Why? With its help, we place all conventional operations that we need on the page. For example, we will start session_start(). The connection to the database will also open.

Here is the code:

Now we are ready to create the visible part of the script if you still want to know how to develop a web app.

User registration (register.php)

In this page, we have two parts. The block of PHP code at the top, and HTML at the bottom.

Entry and exit pages login.php

As in register.php, login.php will have a check at the top of the form and the form to entering below. The form consists of two fields. Everything is very easy and simple.

logout.php

The exit page is even easier. But this page does not need HTML. The function of this page is to exit the application by using the function logout().

The last file is index.php

In this file, you can do anything. Here you can post any links to information.

In this instruction, we tried to show all the steps of how to build a webapp. Still, when you need to develop a web application with many functions and exclusive design, it’s better to work with a development company, unless you are a programmer with many years of experience. Our company Letzgro is able to create any application on your choice. Work  with professionals, choose Letzgro!

Leave a reply