[ Index ]

PHP Cross Reference of JPSpan 0.4 (beta)

title

Body

[close]

/examples/ -> autocomplete_server.php (source)

   1  <?php
   2  // $Id: autocomplete_server.php,v 1.5 2004/11/23 14:10:56 harryf Exp $
   3  /**
   4  * This is a remote script to call from Javascript
   5  */
   6  
   7  define ('JPSPAN_ERROR_DEBUG',TRUE);
   8  require_once  '../JPSpan.php';
   9  require_once JPSPAN . 'Server/PostOffice.php';
  10  
  11  //-----------------------------------------------------------------------------------
  12  class Autocomplete {
  13  
  14      function getWord($fragment='') {
  15          $words = file('data/countrylist.vars');
  16          $fraglen = strlen($fragment);
  17          for ( $i = $fraglen; $i > 0; $i-- ) {
  18              $matches = preg_grep('/^'.substr($fragment,0,$i).'/i',$words);
  19              if ( count($matches) > 0 ) {
  20                  return array_shift($matches);
  21              }
  22          }
  23          return '';
  24      }
  25  
  26  }
  27  
  28  $S = & new JPSpan_Server_PostOffice();
  29  $S->addHandler(new Autocomplete());
  30  
  31  //-----------------------------------------------------------------------------------
  32  // Generates the Javascript client by adding ?client to the server URL
  33  //-----------------------------------------------------------------------------------
  34  if (isset($_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'], 'client')==0) {
  35      // Compress the Javascript
  36      // define('JPSPAN_INCLUDE_COMPRESS',TRUE);
  37      $S->displayClient();
  38      
  39  //-----------------------------------------------------------------------------------
  40  } else {
  41  
  42      //-----------------------------------------------------------------------------------
  43      // Some HTTP Basic authentication
  44      //-----------------------------------------------------------------------------------
  45      $username = 'admin';
  46      $password = 'secret';
  47      
  48      if ( !isset ( $_SERVER['PHP_AUTH_USER'] ) ) {
  49          header('HTTP/1.0 401 Unauthorized');
  50          header('WWW-Authenticate: Basic realm="PHP Secured"');
  51          exit('This page requires authentication');
  52      }
  53      
  54      if ( !( ($_SERVER['PHP_AUTH_USER']==$username) & ($_SERVER['PHP_AUTH_PW']==$password) ) ) {
  55          header('HTTP/1.0 401 Unauthorized');
  56          header('WWW-Authenticate: Basic realm="PHP Secured"');
  57          exit('Unauthorized!');
  58      }
  59      //-----------------------------------------------------------------------------------
  60      
  61      // Include error handler - PHP errors, warnings and notices serialized to JS
  62      require_once JPSPAN . 'ErrorHandler.php';
  63      $S->serve();
  64  
  65  }
  66  ?>


Generated: Fri Nov 26 11:42:46 2004 Cross-referenced by PHPXref 0.6