How can i get user data in php?

In social networking websites like Facebook, Instagram, etc, the username and profile picture of the user that has logged in gets displayed in the header of the website, and that header remains constant, irrespective of the webpage the user has opened. Such functionality can be created by using the session variables
Session variables exist only while the user’s session is active. After the session is complete, the session variables get destroyed. These are unique for each visitor and are generally used to store user-specific information such as the username, profile picture etc, once the user logs in. 
The session variables are used to display logged in user information in PHP.
Project Explanation and Code: 
This is a simple registration system. The register.php page asks for the desired username, email, and password of the user, and then sends the entered data into the database, once the submit button is clicked. After this, the user is redirected to the index.php page where a welcome message and the username of the logged-in user is displayed.
The first step is to create a database, and then a table inside it. The database is named ‘registration’, and the table is named ‘users’. The ‘users’ table will contain 4 fields. 

  1. id – primary key – auto increment
  2. username – varchar[100]
  3. email – varchar[100]
  4. password – varchar[100]
    The ‘id’ will be the primary key, it means that it will be unique for every registered user. It will also auto-increment for every new registration. The data type for username, email and password will be varchar. The size can be adjusted as per the requirement however, 100 is sufficient.
    SQL code for the table:  

sql

CREATE TABLE `users` [

    `id` int[11] NOT NULL AUTO_INCREMENT PRIMARY KEY,

    `username` varchar[100] NOT NULL,

    `email` varchar[100] NOT NULL,

    `password` varchar[100] NOT NULL

]

phpMyAdmin after the database and table creation

Project folder, containing the necessary files

error.php

html

    

        

        

    

Explanation: The error.php file is responsible for holding the error messages of the system. Suppose the user enters the wrong username and password combination, then in such cases, the error messages will be stored in the $error variable, which will then be displayed to the user using ‘echo; function of PHP.
server.php 

php

Chủ Đề