I was desired to make some protected pages for my website. When i was searching hard to get this solution, i got it here at http://www.w3schools.in/php/php-login-without-using-database/.
As i have seen, the username required to be set manually here at the fourth line of the code below.(i don't mind to set it manually as i only need a few protected pages). The code below i copied from url above login.php.
/* 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:index.php");
exit;
} else {
/*Unsuccessful attempt: Set error message */
$msg="<span style='color:red'>Invalid Login Details</span>";
}
}
?>
I would like to ask that, what php code should i put in order to display a username after logged in successfully? Any suggestion? Appreciate your help! I'm still new in php programming.
0 comments:
Post a Comment