Slide 2.6: An indexing demonstration
Slide 2.8: The code sample of indexing
Home         Print version

The Code Sample of Interface


The program below is used to implement the previous interface, which includes the following three buttons:
http://undcemcs01.und.edu/~wen.chen.hu/course/515/2/Index.php
<?php

 # Remove leading and trailing spacing.
 $keyword = trim( $_POST["keyword"] );
 $URL     = trim( $_POST["URL"] );

 # For security, remove some Unix metacharacters.
 $meta    = array( ";", ">", ">>", "<", "*", "?", "&", "|" );
 $keyword = str_replace( $meta, "", $keyword );
 $URL     = str_replace( $meta, "", $URL );

 # MySQL password hid in $_SERVER['DBPASS']
 $password = $_SERVER['DBPASS'];

 if ( $_POST['act'] == "Clear system" ) {
   header( "Content-type: text/plain" );
   system( "/usr/bin/php  Clear.php  $password" );
 }

 elseif ( $_POST['act'] == "Index web pages" ) {
   header( "Content-type: text/plain" );
   system( "/usr/bin/php  Spider.php  $password $keyword $URL" );
 }

 elseif ( $_POST["act"] == "List indexes" ) {
   header( "Content-type: text/html" );
   system( "/usr/bin/php  List.php  $password $keyword" );
 }

 elseif ( $_POST["act"] == "Help" ) {
   header( "Content-type: text/html" );
   $file = fopen( "Help.html", "r" ) or
     exit( "Unable to open file!" );
   while ( !feof( $file ) )
     echo  fgets( $file );
   fclose( $file );
 }

 else {
   header( "Content-type: text/html" );
   echo( "<html><body>" );
   echo( "<h3>No such option: " . $_POST["act"] . "</h3>" );
   echo( "</body></html>" );
 }

?>




      What’s the last thing to go through a fly’s head as it    
      hits the windshield of a car going 70 miles per hour?    
      Its butt.