Horje

Create PHP File for Login Check User and Password

Copy and Paste Following code to login.php In this code, We add Username and Password. You may change according to you. Change: Pass: 123456 Username:username1
login.php
Example: PHP
<?php session_start(); /* Starts the session */
        
        /* Check Login form submitted */        
        if(isset($_POST['Submit'])){
                /* Define username and associated password array */
                $logins = array('Alex' => '123456','username1' => 'password1','username2' => 'password2');
                
                /* Check and assign submitted Username and Password to new variable */
                $Username = isset($_POST['Username']) ? $_POST['Username'] : '';
                $Password = isset($_POST['Password']) ? $_POST['Password'] : '';
                
                /* Check Username and Password existence in defined array */            
                if (isset($logins[$Username]) && $logins[$Username] == $Password){
                        /* Success: Set session variables and redirect to Protected page  */
                        $_SESSION['UserData']['Username']=$logins[$Username];
                        header("location:welcome.php");
                        exit;
                } else {
                        /*Unsuccessful attempt: Set error message */
                        $msg="<span style='color:red'>Invalid Login Details</span>";
                }
        }
?>



Related Articles
How to Login Without Database PHP Login Tutorial

Single Articles
Learn to create HTML Web Worker FilePHP Login Tutorial

Type:
Php
Category:
Web Tutorial
Sub Category:
PHP Login Tutorial
Uploaded by:
Admin



Share on: