i’m trying to make sure that all my user will not logg in during some times so I registered time of start and time of departure in mysql, When they loggin I check first if login et password is the same as in the database
if it is the same, it check if the time is ok, if not it display an errors. but for all cases it does not display the error, but it everytime logg the user on even if he is not authorized because of the wrong time.
I’ve written the following code:
for login:
$sql='SELECT * FROM `gestionnaire` WHERE `login`="'.mysql_real_escape_string($_POST['pseudo']).'"';
$req=mysql_query($sql) or die;
$data=mysql_fetch_assoc($req);
// si on obtient une réponse, alors l'utilisateur est un membre
if ($data['login']==$_POST['pseudo'] AND md5($_POST['pass'])==$data['pass_md5']) {
if(date("H:i")<$data['depart'] OR date("H:i")>$data['depart'])
{
$erreur = '<font color=red>Vous n\'êtes pas autorisé à vous connecter, revenez à '.$data['depart'].'.</font>';
}
else{
}
session_start();
$sql="INSERT INTO `session` SET
`temps` = now(),
`login`='".$data['login']."',
`mouvement`='1'";
mysql_query($sql) or die;
$_SESSION['id'] = $data['id'] ;
$users['id'] = $_SESSION['id'] ;
$_SESSION['login'] = $data['login'];
header('Location: GESTION/index.php');
exit();
}
// si on ne trouve aucune réponse, le visiteur s'est trompé soit dans son login, soit dans son mot de passe
elseif ( md5($_POST['pass'])!=$data['pass_md5']) {
$erreur = '<font color=red>Compte non reconnu.</font>';
}
// sinon, alors la, il y a un gros problème :)
else {
$erreur = '<font color=red>Probème dans la base de données : plusieurs membres ont les mêmes identifiants de connexion.</font>';
}
}
else {
$erreur = '<font color=red>Au moins un des champs est vide.</font>';
}
}
}
Your issue is with
if(date("H:i")<$data['depart'] OR date("H:i")>$data['depart'])because php cannot do this type of comparison.You need to convert your string time to a numerical representation, unix timestamp.
So if
$data['depart']=== ’17:30′ (for 5:30 pm)You need to do something like this:
Now you can do
if($time < $today_depart…