Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/85763-set-a-timer-on-a-login-php-script/
Share on other sites

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.

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
}
?>

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.