PHP interesse |
|
Hallo,
Ik was bezig met een inlog systeem.
Het formulier is ongeveer zo:
<?php
check_login();
?>
<form method="post">
<input type="text" name="login_username">
<input type="password" name="login_password">
<input type="checkbox" name="login_check" value="1">
<input type="submit">
</form>
<?php check_login(); ?> <input type="text" name="login_username"> <input type="password" name="login_password"> <input type="checkbox" name="login_check" value="1">
Nu heb ik een functie die controlleerd of het klopt.
function check_login()
{
$login_username = $_POST['login_username'];
$login_password = md5($_POST['login_password']);
$login_check = $_POST['login_check'];
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$q = mysql_query("SELECT * FROM users WHERE name='".$login_username."' AND pass='".$login_password."'");
$row = mysql_fetch_assoc($q);
if(mysql_num_rows($q) == 1)
{
$_SESSION['user'] = $row['name'];
$_SESSION['level'] = $row['level'];
$_SESSION['id'] = $row['id'];
$_SESSION['logged'] = "1";
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
if($login_check == 1)
{
setcookie("login", $row['id'].";".$row['name'].";".$row['pass'], time()+60*60*24*7);
}
header("location: ".$site_url."");
}
else
{
echo $t_login_wrong;
}
}
}
function check_login() { $login_username = $_POST['login_username']; $login_password = md5($_POST['login_password']); $login_check = $_POST['login_check']; if($_SERVER['REQUEST_METHOD'] == 'POST') { $q = mysql_query("SELECT * FROM users WHERE name='".$login_username."' AND pass='".$login_password."'"); { $_SESSION['user'] = $row['name']; $_SESSION['level'] = $row['level']; $_SESSION['id'] = $row['id']; $_SESSION['logged'] = "1"; $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; if($login_check == 1) { setcookie("login", $row['id'].";".$row['name'].";".$row['pass'], time()+60*60*24*7); } header("location: ".$site_url.""); } else { } } }
Maar hij pakt nu de POST variabeles niet, weet iemand waar dit aan kan liggen?
Alvast bedankt!
Mvg,
Sar
btw, het formulier en dergelijke is niet het officiele formulier, maar dit is een voorbeeld code...
|