ISCL is a Intelligent Information Consulting System. Based on our knowledgebase, using AI tools such as CHATGPT, Customers could customize the information according to their needs, So as to achieve

How to Create a Simple Login With PHP

3

    Input Form

    • 1). Using your HTML editor or notepad, create a new Web page and save it as "login.php". Create a form and use the "post" method value. Example code follows:

      <form action="login.php" method="post">

      </form>

    • 2). Add two input boxes within the form for the username and password fields. Use the "password" type for the password box. Example code follows:

      <form action="login.php" method="post">

      <input type="text" name="username">

      <input type="password" name="password">

      </form>

    • 3). Add a submit button which will be used to submit the form. Example code follows:

      <input type="submit" value="Submit">

    PHP Code

    • 1). Declare two variables that will hold the values from the form submission. Call them "username" and "password". Example code follows:

      <?php

      $username = $_POST['username']

      $password = $_POST['password']

      ?>

    • 2). Write an "if" statement to check if the form has been submitted. The code for this is:

      if($_SERVER['REQUEST_METHOD'] == "POST") {

      }

    • 3). Write an "if" statement to check the username and password against two values of your choice. Include the "header" statement to redirect the user accordingly. Example code follows:

      if ($username == "user" && $password == "pass"){

      header('Location: http://www.example.com/success.html');

      die();

      else

      {

      header('Location: http://www.example.com/loginfailed.html');

      die();

      }

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.