Reputation: 37
I have a page for my students to login for attendance, really simple, just a name and student id box and it clocks them for the day with a time recording and all that. However, I am trying to implement a 'lock out' system so that they cannot mark attendance outside of class time. The days are Tuesday and Thursday from 11-1215. I can get the time lockout to work or not work if the time is right, but they days are not working, and I don't really know why. Any help would be appreciated.
if (date('G')<=11 || date('G')>= 12 && date('N') !=3 || date('N') !=5)
{
header ('Location: /noattend.php');
exit();
}
Upvotes: 0
Views: 44
Reputation: 44714
I'd recommend brushing up on how Operator Precedence is performed in PHP. In this specific scenario, your conditions will be evaluated from left-to-right, which probably isn't what you intended.
Instead, group your conditions appropriately to meet your logical criteria (and change the logical OR
for the day of the week to a logical AND
, thanks @enhzflep):
if ((date('G')<=11 || date('G')>= 12) && (date('N') !=2 && date('N') !=4))
{
header ('Location: /noattend.php');
exit();
}
Upvotes: 2