Friday, 14 April 2017

PHP login and get user information

Question: How can I get the user information when the user successfully login?



Here is my login.php code





if($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
// mysql connect function here....
// mysql query here....
$sql = "SELECT * FROM user_accounts WHERE username = '$username' and password = '$password'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);


if($count == 1) {
session_register(username);
session_register(password);
header('location: index.php');
}
else {
$error = "Invalid Username or Password Please Try Again";
}

}

?>


Username :
Password :





and here is my index.php code





session_start();
if(!session_is_registered(username)){
header("location:login.php");
}
$username = session_is_registered(username);
$password = session_is_registered(password);
echo $username;

echo $password;
?>



Example: This is the database info.




User ID --> 001
Username --> admin
Password --> admin



When I echo $username and $password the result for username = 1 and for password = 1. I wanted the result is username = admin and password = admin.



How can I get the username and password that logs? cause I need it to be query so I can get his/her e.g. First Name, Last Name.
I already get this but I forgot on how to do it. =)



Thank You so much for your replies. =)

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...