title: Using a php function with a 30 minute interval between each execution
body: <p>The function i want to execute with a 30 minute interval between each execution is the <strong>validate_digest($realm, $users)</strong>:</p>
  <pre><code>$realm = 'Restricted area';
  $users = array('admin' =&gt; 'admin', 'guest' =&gt; 'guest');
  $username = validate_digest($realm,$users);
  $ati = ($_SERVER['REQUEST_TIME'] % (30*60));
  
  function send_digest($realm) {
      header('HTTP/1.1 401 Unauthorized');
      header('WWW-Authenticate: Digest realm=&quot;'.$realm.'&quot;,qop=&quot;auth&quot;,nonce=&quot;'.md5(uniqid()).'&quot;,opaque=&quot;'.md5($realm).'&quot;');
      die('You need to enter a valid username and password');}
  
  function validate_digest($realm, $users) {
         unset($_SERVER['PHP_AUTH_DIGEST']);
         unset($digest);
         unset($digest_info);
         unset($request_digest);
  
       if (!isset($_SERVER['PHP_AUTH_DIGEST'])) {send_digest($realm);}
       $username = parse_digest($_SERVER['PHP_AUTH_DIGEST'], $realm, $users);
       if ($username === false) {send_digest($realm);}
       return $username;
        }
  function parse_digest($digest, $realm, $users) {
  
       $digest_info = array();
  
       foreach (array('username','uri','nonce','cnonce','response') as $part) {
       if (preg_match('/'.$part.'=([\'&quot;]?)(.*?)\1/', $digest, $match)) {
          // The part was found, save it for calculation
           $digest_info[$part] = $match[2];
       }else{
          return false;
       }
      }
  
  
     if (preg_match('/qop=auth(,|$)/', $digest)) {
        $digest_info['qop'] = 'auth';
     }else{
        return false;
     }
  
     if (preg_match('/nc=([0-9a-f]{8})(,|$)/', $digest, $match)) {
        $digest_info['nc'] = $match[1];
     }else{
        return false;
     }
  
     $A1 = $digest_info['username'] . ':' . $realm . ':' . $users[$digest_info['username']];
     $A2 = $_SERVER['REQUEST_METHOD'] . ':' . $digest_info['uri'];
     $request_digest = md5(implode(':', array(md5($A1), $digest_info['nonce'],
                    $digest_info['nc'],$digest_info['cnonce'], $digest_info['qop'], md5($A2))));
  
     if ($request_digest != $digest_info['response']) {
        return false;
     }
     if (!isset($_SERVER['PHP_AUTH_DIGEST'])) {send_digest($realm);}
   }
  </code></pre>
  <p>I was planning on either using Ajax, JavaScript or JQuery but i don't really know how to work with either of those programming languages.</p>