PHP giriş almak ve kullanıcı bilgileri

0 Cevap

Kullanıcı başarıyla giriş yaptığınızda Question: nasıl kullanıcı bilgi alabilirim?

İşte benim login.php koddur

<?php
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";
  }

}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?=$error=?>
Username : <input type="text" name="username">
Password : <input type="password" name="password">
<input type="submit" />
</form>


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

I $username ve username = 1 için ve şifre = 1. Ben sonuç username = yönetici ve şifre = admin istedim $password sonucu echo.

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. =)

0 Cevap