Internal Server Error

Discussion in 'Apache' started by noobi, Jun 17, 2008.

  1. #1
    Hi Everybody.
    I'm trying to learn PHP from a book. I'm using Xampp 1.6.6a on WinXPSP2 (http://www.apachefriends.org/en/xampp-windows.html).
    The book told me to write a librarian system that any file could access. The book's a little old because I bought it from my ex-teacher, but after a little research I couldn't find anything wrong with the code. It told me to put the following in the .htaccess file in the Document Root.

    #<?Inc("templ")?>
    #<?Block("DefaultGlue"," | ")?>
    #<?Block("Template","default.tmpl")?>
    #<?Block("Title","Test server")?>
    # Associate the name of the handler with a specific file
    # Action templhandler "/lib/templ/TemplateHandler.php?"
    # We want the handler to process a document of this type
    # AddHandler templhandler .html .htm
    # Associate PHP with the php4 extension
    AddType application/x-httpd-php php4
    # Associate the name of the handler with a particular file
    Action libhandler "/lib/libhandler.php4?"

    It also told me to write the /lib/libhandler.php4 file like this:

    <?
    // First of all, we set our directories for module search
    // According to convention, this is the current directory
    $INC[]=getcwd();

    // Check whether the user tries to start the handler directly,
    // bypassing Apache. For example, this is possible by typing
    // the lib/libhandler.php address in the browser address box
    // Since the address entered by the user is always passed
    // to the $_SERVER[REQUEST_URI] environment variable, we must set off some type of
    // alarm if the passed address string is found in the name
    // of the handler file (regardless of the case of the letters)
    // We can't forget to trim the part of the string that follows
    // the "?" character, because this part will hinder us
    // when comparison to the file name is performed
    // Unfortunately, this seems to be the only platform-independent
    // way of checking the legality of the handler start
    $FileName=strtr(__FILE__,"\\","/");
    $string= strtr(($_SERVER['REQUEST_URI']),"\\","/");
    $RegName=str_replace("\?","", $string);
    // The original version used regular expressions here, but they went out of date and
    // the book didn't tell me anything about PCRE. I looked it up on php.net and I tried to
    // update it through the instructions given, but I was hugely unsuccessful.
    // After trying fnmatch() and being told by my browser that it was undefined, I used
    // strcasecmp() with quotemeta(). This seems to work.
    if(strcasecmp(quotemeta($RegName),$FileName)) {
    // Display the error message
    include "libhandler.err";
    // Write the user's data to the log
    $f=fopen("libhandler.log","a+");
    $date = date("d.m.Y H:i.s");
    echo $date."<br>";
    $ip = $_SERVER['REMOTE_ADDR'];
    echo $ip."<br>";
    fputs($f, $date.$ip);
    fclose($f);
    // Exit
    exit;
    }

    // If everything's all right, correct the environment variables
    // in accordance with the address requested by the user
    @putenv($_SERVER['REQUEST_URI']=
    $_ENV['QUERY_STRING']=
    ereg_Replace("^[^?*\\?","",getenv("QUERY_STRING"))
    );
    parse_str($QUERY_STRING);
    // Include the librarian
    include "librarian.phl";
    // Some other actions can be performed here....
    // ....
    // Start the script requested by the user
    chdir(dirname($_SERVER['REQUEST_URI']));
    include $_SERVER['REQUEST_URI'];
    ?>
    However, I cannot use the functions in the library system as I get a blank page back when I try. If I access this file directly then I get an Internal Server error for too many internal redirects and another internal server error while trying to use an error document. I haven't changed the default error document.

    Hoping someone can help
    Thanks in advance
    Noobi
     
    noobi, Jun 17, 2008 IP
  2. noobi

    noobi Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    RegEx seems to work when it's not part of an 'if' statement, btw.
     
    noobi, Jun 17, 2008 IP