Creating Login with PHP

            Here, let’s assume that register.php and database have been created and we just need to create login.php so that the user can login to access further features.

  1. Required files (already created)
  2. Register.php for register form
  3. Database for registering and logging in
  4. config.php to connect
  5. Index.php for the landing page, just HTML and CSS, don’t forget to add an href on the login button to login.php so you can connect.
  6. If it has not been created, it can be seen in article 05. Register with PHP.
  7. Create a login feature
  8. Please create login.php, fill it with the required code such as:
  9. Require_once(config.php) to connect with config.php and use functions in config.php
  10. After that check the login button has been created or not by using isset
  11. Perform a filter on the username and password so that the inputted data can enter the database.
  12. Next do the query:

SELECT * FROM users WHERE username=:username OR email=:email

  • In the query we use logical OR so that the user can login with the email or username that has been created.
  • Bind parameters and query execution

$params = array(

    “:username” => $username,

    “:email” => $username



  • After the query is executed, we retrieve the results using the fetch() function;

$user = $stmt->fetch(PDO::FETCH_ASSOC);

That is, we take the query result as an associative array

  1. The fetch() function will return NULL if there is no data, so we will create a condition with if
  2. Next we verify the password that has been created by the user with the password in the database by:

if(password_verify($password, $user[“password”]))

  • The password_verify function will return true if the password entered is the same as the password in the database
  • Next create a session and redirect it to the timeline.php page with header()
  • Create a timeline page
  • Before making the code on the timeline.php page, we first create the auth.php file to check whether the user is logged in or not
  • Code file auth.php with


if(!isset($_SESSION[“user”])) header(“Location: login.php”);

to use the $_SESSION variable, you must first call the session_start() function, then check whether you are logged in or not with the code below

-Create and fill in the timeline.php code with require_once(“auth.php”) so that timeline.php can only be opened by those who are logged in and fill in the display with HTML and CSS as desired
-Login has been successfully entered and access timeline.php which can only be accessed by those who have logged in.
-Logout with PHP
-Open it and create a logout.php file
-Fill the file with the code:
-Session_start(); so that the $_SESSION variable can be used
-Session_start(“user”); to destroy and delete the variable $_SESSION[“user”];
-Header(“Location: index.php”); to return to the main page
-Destroying is complete and the user will return to the main page

  • Conclusion and Closing

By creating a login feature, certain users will access certain pages that cannot be accessed by normal users to be able to enter that page.

The need for digital IT is needed in daily activities, Bead IT Consultant is the right choice as your partner, visit our website by clicking this link:


  1. I needed to thank you for this great read!! I absolutely enjoyed every little bit of it. I have you saved as a favorite to look at new things you post…

  2. Thanks for one’s marvelous posting! I seriously enjoyed reading it, you happen to be a great author. I will remember to bookmark your blog and will come back later in life. I want to encourage you to definitely continue your great work, have a nice evening!

  3. The contemporary affordable world demands an engaging online visibility. Partnering with the best electronic marketing solutions is the only method to accomplish this goal. We create personalized, strong, and creative digital techniques. To make sure that every local business owner, web site owner, as well as business meets their desire objective.

  4. Thanks a lot for sharing this with all people you actually understand what you’re speaking approximately! Bookmarked. Please also discuss with my website =). We may have a link exchange contract between us

  5. Digikrish
    245 W 30th St, Ste12A
    New York, NY 10001
    p4: 646-880-6898

  6. Для вас приемлемы служба косметолога, фокуса помощи, трихолога, физиотерапии, ЭКО и прочих технологий, лекарственного массажа, лучшей устранения веса, ЛФК, бальнеотерапии, процедурного кабинета и прочие потенциал реставрационной медицины, лавка лечебных упражнений, такими как катетеризация уринозного пузыря, кинезиотейпирование, миниабдоминопластика, операция и пункция сустава, и еще гальванотерапия эрозии шейки матки, эндометриоза и еще ячменя. В кабинете косметической медицине у вас есть возможность оторваться нате сеансе массажа, изучить тенденция антицеллюлитного массажа, сшибить монету консультацию косметолога, поишачить с миостимулятором, зашибить монету консультацию относительно криотерапии, навести погреб ультразвук. для возлюбленная находилась загоришься, необходимо воплощаться анфилада договоров: за глаза у больного болезней воспалительной натуры, неделимость дерматологического покрова в должностях, идеже будут упрямиться прокладки с электродами равным образом т.буква. несомненно же, они необходимы, в надежде задушить инфекцию да милая, буква экстренной медицине, только тем временем, необходимо понимать, что такое? что бы ни они быть обладателем неисчислимые сторонные результаты немного непредсказуемыми результатами, и еще не счесть противопоказаний. Фролка-Эссенс деловито употребляется около онкологических заболеваниях, таких как, для того возрождения после семилучевой (а) также химиотерапии.

  7. Gforce teeth Introducing the ultimate solution for bleeding and receding gums, cavities, and bad breath 100% all-natural and non-GMO formula that is GMP certified and backed by a 60-day money-back guarantee

  8. Don’t Let Tinnitus Control You! cortexi
    is a breakthrough dietary supplement designed to target the root cause of this misunderstood condition. Formulated with all-natural plant extracts, Cortexi has been carefully crafted based on extensive research analysis by specialists worldwide.

Leave a Reply

Your email address will not be published.