mariocesar Posted January 13, 2008 Share Posted January 13, 2008 Hello, please help, I build a site, you can call it an internal info system for sales reps. (24 sales reps.) is working with a php. login system, each one with his own user and password, there is very private info on close to 20 php. pages about sales and prices, my question is how can I let them get access to the site from 9.00 am to 5.00pm and not access at all on weekends, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/ Share on other sites More sharing options...
twostars Posted January 13, 2008 Share Posted January 13, 2008 Hello, please help, I build a site, you can call it an internal info system for sales reps. (24 sales reps.) is working with a php. login system, each one with his own user and password, there is very private info on close to 20 php. pages about sales and prices, my question is how can I let them get access to the site from 9.00 am to 5.00pm and not access at all on weekends, thank you. Use the date() function. EG: <?php $day = date('l'); # Get day if ($day == "Saturday" || $day == "Sunday") # If its the weekend, deny access echo "No access on weekends, sorry!"; else # If its a weekday, continue processing { $ampm = date('a'); # Get am or pm $hour = date('h'); # Get current hour if ($ampm == 'am') # If its am, we want to go through and check the hours allowed in "am". { if ($hour >= 9 && $hour < 12) # If its after and including 9am, and before 12 am (as 12am is a totally different time), grant access { echo "You have access"; } else # Deny access echo "You do not have access at this particular time, sorry."; } else # If its pm, check the hours allowed for "pm". { if ($hour == 12 || $hour < 5) # If the hour is 12pm, or is below 5pm (up to 4.59pm), grant access { echo "You have access"; } else # Deny access echo "You do not have access at this particular time, sorry."; } } ?> That should work.. its rough, but it'll work I think. Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/#findComment-437723 Share on other sites More sharing options...
Daukan Posted January 13, 2008 Share Posted January 13, 2008 He is an example, haven't tested it though <?php $hour = date('H');//hour 1-24 $dayofweek = date('N');//numeric day of week 1=mon, 7=sun if($hour < 9 || $hour > 16 || $dayofweek > 5) { echo 'Could not be logged in. Site is closed'; }else { //login code } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/#findComment-437725 Share on other sites More sharing options...
twostars Posted January 13, 2008 Share Posted January 13, 2008 He is an example, haven't tested it though <?php $hour = date('H');//hour 1-24 $dayofweek = date('N');//numeric day of week 1=mon, 7=sun if($hour < 9 || $hour > 16 || $dayofweek > 5) { echo 'Could not be logged in. Site is closed'; }else { //login code } ?> Nice, I can see that should work. Why didn't I think of 24 hour time? *D'OH!* Also much smaller than mine. Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/#findComment-437726 Share on other sites More sharing options...
mariocesar Posted January 13, 2008 Author Share Posted January 13, 2008 Thanks, this takes care the week days, from 9.00 am to 5.00 pm, how can I block the access on weekends, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/#findComment-438377 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 The $dayofweek variable takes care of blocking it on weekends. Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/#findComment-438379 Share on other sites More sharing options...
mariocesar Posted January 20, 2008 Author Share Posted January 20, 2008 Hi the day timing is working but the weekend part is not, still allow access to the users on weekends, any idea why? here is the code <?php $hour = date('H');//hour 1-24 $dayofweek = date('N');//numeric day of week 1=mon, 7=sun if($hour < 9 || $hour > 16 || $dayofweek > 5) { echo 'Could not be logged in. Site is closed'; }else { //login code } ?> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/#findComment-444566 Share on other sites More sharing options...
revraz Posted January 20, 2008 Share Posted January 20, 2008 N only works for PHP 5.1.0, you need to use w if you are on a lower version and you have to check for 0 or 6 instead of greater than 5 Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/#findComment-444576 Share on other sites More sharing options...
ratcateme Posted January 20, 2008 Share Posted January 20, 2008 The script works fine on my server have you checked the date and time on your server because the script is fine add in a echo $dayofweek; to see what number you are getting Scott. Quote Link to comment https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/#findComment-444577 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.