Menu
What is th best to keep trace of the password after someone logged to the site. I mean where sould i put the password to take it and check if it’s valid each time a page is loaded.
Exept if you have a better idea.
[code=php]<?php
$loginfailed = false;
if(isset($_POST['action'])&&($_POST['action']=='login')){
$password = md5($_POST['password']);
$username = $_POST['username'];
include('users.php');
if(isset($users[$username])&&($users[$username]['password']==$password)){
setcookie('lib-login[user]',$username,time()+60*60);
setcookie('lib-login[pass]',$password,time()+60*60);
header('location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/index.php');
die;
}else{
$loginfailed = true;
}
}
?><html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
td {
background-color: #EEEEEE;
}
input {
border: 1px inset #404040;
background-color: #EEEEEE;
}
-->
</style>
</head>
<body onload="document.form1.username.focus();">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="middle" style="background-color:white;"><p>
<?php if($loginfailed){echo 'Not a Valid Username/Password!';}else{echo 'Amasing what 100% pure CSS can do to a webpage...';} ?>
</p>
<form name="form1" method="post" action="login.php">
<table border="0" cellpadding="3">
<tr>
<td colspan="2"><p>Welcome to the Lib</p>
</td>
</tr>
<tr>
<td><p>Username</p></td>
<td> <input name="username" type="text" id="username2" onfocus="this.style.borderColor='#330099';this.style.backgroundColor='#FFFFFF';" onBlur="this.style.borderColor='#EEEEEE';this.style.backgroundColor='#EEEEEE';"> </td>
</tr>
<tr>
<td>Password</td>
<td> <input name="password" type="password" id="password" onfocus="this.style.borderColor='#330099';this.style.backgroundColor='#FFFFFF';" onBlur="this.style.borderColor='#EEEEEE';this.style.backgroundColor='#EEEEEE';"> </td>
</tr>
<tr align="center">
<td colspan="2"> <input type="submit" name="Submit" value="Submit" style="border: 1px outset #404040;">
<input name="action" type="hidden" id="action" value="login"> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
[/code]
[code=php]
<?php
$writeable = false;
if(isset($users[$_COOKIE['lib-login']['user']])&&($users[$_COOKIE['lib-login']['user']]['password']==$_COOKIE['lib-login']['pass'])){
if($users[$_COOKIE['lib-login']['user']]['perms']['ALL']>=2){
$writeable = true;
}else{
$writeable = false;
}
}else{
header('location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/login.php');
die;
function logout(){
setcookie('lib-login[user]',null,1);
setcookie('lib-login[pass]',null,1);
setcookie('lib-login',null,1);
header('location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/login.php');
}
?>
[/code]
<i>
</i><?php
//Déclaration de variables
$ID_Login = md5(microtime());
//Déclaration des fonctions
Function CreerCookie()
{
if (setcookie("Login", $ID_Login, time()+60*60*12))//expire dans 12 heures
{
$InsertCookie = "INSERT INTO Logged VALUES (
'".$ID_Login."','','','".Date("Y-m-d H:i:s")."');";
<i> </i>//Faire un test et effacer le cookie si yé pas entré dans db
<i> </i>mysql_query($InsertCookie,$db);
}
else
{
echo "Une erreur est survenue, assurez-vous que votre navigateur accepte les cookies";
<i> </i>//Informations de déboggage------------------A effacer
<i> </i>echo "<br />Bou :( P.S.on devrait pas voir la forme eventuellement";
}
}
0.1.9 — BETA 4.27