Web Programming

How to Implement a Very Basic Login System in PHP Through Arrays

Learn arrays and loops in PHP by implementing a simple service that allows users to log in to a system and to read articles.

Angelica Lo Duca
Geek Culture
Published in
9 min readNov 16, 2021

--

Photo by Florian Olivo on Unsplash

In this tutorial I illustrate a practical example to learn arrays in PHP. The idea is to implement a service that allows users to log in to a system and to view articles. The service receives the user’s username and password via GET. Do not worry if you do not know what is GET. You will learn it in this article :) Then it checks that they are correct. If so, it proceeds as described below, if not, it does nothing.

The list of users is statically kept in an array, as is the list of articles. Depending on the user’s role, the service shows a different screen. The possible user roles and the related screens to show are:

  • administrator: the service shows all system users and their roles, but does not show user passwords.
  • reader: the service shows all the articles present in the system, without the name of the authors
  • writer: the service allows you to view all the articles written by the user.

1 Associative Array

--

--

Angelica Lo Duca
Geek Culture

Researcher | +1M Views | I write on Data Science, Python, Tutorials, and, occasionally, Web Applications | Author of Data Storytelling with Altair and AI