www.webdeveloper.com
Results 1 to 8 of 8

Thread: Allow Accsess Between Certain Times

  1. #1
    Join Date
    Oct 2005
    Posts
    593

    Allow Accsess Between Certain Times

    Hi there,

    Is it possible to allow accsess to a certain part of the website on certain days at certain times? Say.. Monday 7-9 Pm?

    Fet

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    Sure.
    PHP Code:
    <?php
    $day 
    = (int) date('N');
    $hour = (int) date('H');
    if(
    $date or $date or $hour 19 or $hour 20)
    {
      echo 
    "<p>This page is only viewable Mon.-Fri. from 7pm to 9pm Eastern US time</p>";
      exit; 
    // alternatively, don't exit but instead use an else block for the rest of the page
    }
    // rest of page here...
    Of course, you'll want to flesh it out to make sure the HTML is complete and valid, but this should give you something to work with.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2006
    Posts
    140
    Personally, I'd just do 'else echo file_get_contents(FILENAME);
    Is that bad practice?

  4. #4
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Conditional statements are fine for this if you never change your timetable and the times are very simple. For more complicate timetables consider a look-up table.

  5. #5
    Join Date
    Nov 2006
    Posts
    41
    something like this perhaps?

    Code:
    function TimeCheck($Allowed = array())
    {
      $now = time();
      foreach($Allowed as $key => $value)
      {
    	if($now > $Allowed[$key] && $now < $Allowed[++$key])
    	{
    		return true;
    	}  
      }
      return false;
    }
    Disclamer, I'm tired and that is untested.

  6. #6
    Join Date
    Nov 2006
    Posts
    140
    I think its more like:
    PHP Code:
    function TimeCheck($Allowed = array())
    {
      
    $day = (int) date('N');
      
    $hour = (int) date('H'); 
      return 
    $allowed[$day]->[$hour] == 1;

    or
    PHP Code:
    $day = (int) date('N');
    $hour = (int) date('H'); 
    if (
    $allowed[$day]->[$hour]) echo file_get_contents("./MyPage.html");
    else echo 
    file_get_contents("./CheckLater"); 

  7. #7
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by yitzle
    PHP Code:
    $allowed[$day]->[$hour] == 1
    That's not valid syntax. What's it supposed to be doing?

  8. #8
    Join Date
    Nov 2006
    Posts
    140
    Oops. That's Perl.
    It (in Perl) would check to see if the hour inside the day is set to '1'.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles