View unanswered posts | View active topics It is currently March 30th, 2017, 9:56 am

Reply to topic  [ 4 posts ] 
 QuickPHP Mods 
Author Message

Joined: December 22nd, 2008, 7:02 am
Posts: 20
Post QuickPHP Mods
Module: Directory Listing
Version: 1.2
Last Updated: 2008-12-23

Okay Zach, Just to show ya how i Enjoyed QuickPHP, I thought I would share this little gem i wrote up. I took the idea from another thread here, and thought I would try my hand at showing ppl, that the QuickPHP Mod is a pretty nice tool to have. Anyways the post wanted QuickPHP to provide a Directory List for Directories which didnt have a index.php. So I got to thinking....
Since QuickPHP Mod runs before, couldnt we make a check to see if this was a directory url or a file url. and if it was a directory url, we can check for the existance of an index.
if none exists, than we can change the RequestURI to our shiny Directory Lisings....

Okay, so a long time ago, I knew about Xitami Web Server (Another favorite of mine), and I knew it had a template for directory listings, so I figured that wud cut my work in half, cuz now I didnt need to design a page from the ground up. after a couple of hrs, and debugging the QuickPHP Mod, to get it to do wut I wanted, And Converting the Xitami Directory Template into a pure php Directiory Listings. I think I finally got it.

Okay, so lets get started eh?

These Mods use my custom QuickPHP_ReqMod Loader which is posted below

File: QuickPHP_ReqMod.php

File: mods/httpdir.php
Yes, create a new folder where QuickPHP is located
   $mod['version'] = '1.2';
   if($mod['opendir']=(is_dir($ScriptFilename) && !is_file($ScriptFilename.'/.lock')))

As u can see its a very simple module, which just checks the uri for a valid directory :)

now in yer web directory, we will create a new folder quickphp. this is where we are gonna put our new handy dandy script as well as some images
File: quickphp/httpdir.php

   if(!isset($_GET['dir']) ||
      strlen($dir=urldecode($_GET['dir'])) &&
      header("HTTP/1.0 404 Not Found");
      include("{$dir}/index.".($hi==1 ? 'php':'html'));
   function units($bytes=0)
            if ($bytes<=0)
                  return '0 Byte';
            $convention=1024; //[1000->10^x|1024->2^x]
            $s=array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB');
            return round($bytes/pow($convention,$e),2).' '.$s[$e];
   $order=(isset($_GET['order']) && preg_match('/^[nstx]{2,3}$/i',$_GET['order']))
   $dorder = substr($order,0,1);

<HTML><TITLE>Directory listing of <?php echo $urlbase; ?></TITLE><BODY>
<H3>Index of:&nbsp;
<?php if(!is_null($urlparent)) { ?>
   <A HREF="<?PHP echo $urlparent; ?>">
   <IMG SRC="/quickphp/dir_up.gif" BORDER=0 ALT="Up to <?php echo $urlparent; ?>"></A>
<?php }    echo $urlbase; ?></H3>
<TR><TH ALIGN=LEFT><A HREF="<?php echo "{$urlbase}?order={$name_reorder}"; ?>">Name</A></TH>
     <TH ALIGN=RIGHT><A HREF="<?php echo "{$urlbase}?order={$size_reorder}"; ?>">Size</A></TH>
   <TH ALIGN=RIGHT><A HREF="<?php echo "{$urlbase}?order={$time_reorder}"; ?>">Modified</A></TH></TR>
      while(($file=readdir($dh)) !== false)
         if($file[0]=='.') continue;
      // Still need sort order
      foreach($files as $idx=>$file)
<A HREF="<?php echo "{$urlbase}{$file}"; ?>"><IMG SRC="<?php echo $icon; ?>" BORDER=0><?php echo $file; ?></A></TD>
<?php if($ftype[$idx]===false) { ?>
<?php } else { ?>
<TD ALIGN=RIGHT><?php echo units($fsize[$idx]); ?></TD>
<?php } ?>
<TD ALIGN=RIGHT><?php echo date("d-M-Y H:i:s", $ftime[$idx]); ?></TD></TR>
<?php }
} ?>
<P><I>Powered by <A HREF="">QuickPHP</A></I>

And there ya have it :) (BTW I also ripped the gif images from xitami as well, )

Yes, I know, the Sorting routine isnt even made. I was gonna add it, but thought I wud show ya What could be done with QuickPHP :) And to stir up others to post some script ideas as well :)

Update: U can create .lock in directories where u don't have an index.php and don't want directory access.

ANyways, Enjoy :)

Last edited by Laffin on December 24th, 2008, 4:12 pm, edited 3 times in total.

December 22nd, 2008, 9:17 pm

Joined: December 22nd, 2008, 7:02 am
Posts: 20
Post QuickPHP Mod: Custom Error Pages
Module: Custom 404 Error Pages
Version: 1.3
Last Updated: 2008-12-22

Instead of creating more threads with diff Modules, I thought it wud be better to keep Mods in their own thread

Okay Another Module this time for custom 404 error pages.
Please note the filepath/name convention uses my directory layout, posted in another thread.

This Module allows u to create your own custom 404 pages :)
Its very simplistic, but it does get the job done :) (Again this was a template from xitami, thought it wud be a nice conversion)

File: bin/QuickPHP_ReqMod.php

File: bin/mods/errors.php
   if(!(isset($mods['httpdir']) && $mods['httpdir']['opendir']) &&

File: web/quickphp/errors.php
   header("HTTP/1.0 404 Not Found");
   $errors=array(0=>'Unknown',404=>'File Missing');
   $errcode=(isset($_GET['err']) && ($errcode=intval($_GET['err'])) && isset($errors[$errcode]))?$errcode:0;
<H2>Error <?php echo $errcode; ?></H2>
<H3><?php echo $errors[$errcode]; ?></H3>
<?php if(!is_null($message)) { ?>
<P><?php echo $message; }?>
<TR><TD>Server       </TD><TD><?php echo $_SERVER["SERVER_SOFTWARE"]; ?></TD></TR>
<TR><TD>Name         </TD><TD><?php echo $_SERVER["SERVER_NAME"]; ?></TD></TR>
<TR><TD>Host         </TD><TD><?php echo $_SERVER["HTTP_HOST"]; ?></TD></TR>
<TR><TD>URI          </TD><TD><?php echo $uri; ?></TD></TR>
<TR><TD>Your IP      </TD><TD><?php echo $_SERVER["REMOTE_ADDR"]; ?></TD></TR>
<TR><TD>Your browser </TD><TD><?php echo $_SERVER["HTTP_USER_AGENT"]; ?></TD></TR>

Update: I noticed that the URI was for the custom error page, I added some more code so it displays the original URI :)

Last edited by Laffin on December 24th, 2008, 4:13 pm, edited 2 times in total.

December 23rd, 2008, 7:00 am

Joined: December 22nd, 2008, 7:02 am
Posts: 20
Post QuickPHP Mod: Module Loader
Name: Module loader
Version: 1.4
Last Updated: 2008-12-23

Not exactly a module, but the main QuickPHO_Mod script for loading modules. I have been using this as a means to load up modules, and do some common things between modules.

New in 1.3
Added comments on using the debug log systems (Yes, u can use the original system, or the mod_loader system)
Added module detection, if the module dusn exist than there is no sense in trying to load up the module :) It just returns gracefully.

The Original Post
Okay Zach, after creating my two Mods above (Initially they were the same Mod, but I just decided to seperate them).
I ran into a huge problem.

U cant have more than 1 Rewrite module, as it doesnt update the other variables!

What a nightmare... so I thought, well if there was a module loader that can do this for u this would be great.
However another problem introduced itself, remember the feature request I made about the debug log? Appending instead of overwriting.... Yeah this is one of them instances where ya wished the feature was already built. Sometimes when yer coding ya just get introduced to the snowball affect, and it just dusn seem to end.... I cuouldn't examine wut was going on in the module loader because I couldnt tell what the variables where, as the log file kept overwriting itself.

Okay so I needed a new debug log function for a new mod loader so modules can play nice. Fortunately PHP does make some things very easy for u. and others can be a pain.

so I turned off DebugLog feature, and wrote a simple one with ob_start buffering system (simple). But I think I will expand it to produce some extra info (timestamp and startup values)

I think I got it all worked out now, well so far it works pretty good.


to keep some things simple, I use the basename of the module, the mod_load function adds other information to generate a ModuleSignature as well as the filename.
I think I got the RequestURI update detection working properly.
and the variable dump routine is a nice one, cuz now i can see in the log file something like this
'RequestURI' => "/"
'RquestHeaders' => "Host: localhost:8088
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/2008120122 Firefox/3.0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cache-Control: max-age=0
Loading Module: acesslog

      Updated 'ModuleSignature' => " mod_loader/1.4 mod_acesslog/1.0"
Updated 'mods' => array(
    'acesslog' => array(
        'version' => "1.0"
Loading Module: httpdir
Updated 'RequestURI' => "/quickphp/httpdir.php?dir=C%3A%5Cquickphp%5Cweb%5C%5C"
Updated 'ModuleSignature' => " mod_loader/1.4 mod_acesslog/1.0 mod_httpdir/1.2"
Updated 'mods' => array(
    'acesslog' => array(
        'version' => "1.0"
    'httpdir' => array(
        'version' => "1.2"
        'opendir' => true
Loading Module: errors
Updated 'ModuleSignature' => " mod_loader/1.4 mod_acesslog/1.0 mod_httpdir/1.2 mod_errors/1.3"
Updated 'mods' => array(
    'acesslog' => array(
        'version' => "1.0"
    'httpdir' => array(
        'version' => "1.2"
        'opendir' => true
    'errors' => array(
        'version' => "1.3"

I updated the above posts/mods with the new versions to conform to the mod_loader :)

WooHoo, Finally the Script!
File: QuickPHP_ReqMod.php
      $ModuleSignature.=' mod_loader/1.4';

      // U can use the Default Log System
    $DebugLog = false;
     // Or U can use mod_loader's log system   
    // $logfile='/quickphp/logs/quickphp.mod.log';
    // Or not have a debug log for QuickPHP_ReqMod system
    function display_var($varname,$var,$ind=0)
         $indent=str_repeat(' ',$ind*4);
         $text=$indent."'{$varname}' => ";
           foreach($var as $idx => $val)
              $text.= $indent .')';
       } elseif($typ=(is_string($var)?1:(is_numeric($var)?2:0))) {
          $text.=($qt=($typ==1?'"':'')). $var . $qt;
       } elseif(is_bool($var)) {
         } else {
            $text.= 'resource ['. gettype($var) .']';
         return $text."\n";
    function mod_load($name)
       static $qpv=array();
          echo "Loading Module: $name\n";
       else {
          echo "Missing Module: $name\n";
           $qpv=array(   array(1,'DebugLog'), array(1,'RequestURI'), array(1,'RequestHeaders'), array(1,'UniqueID'),
                    array(1,'ModuleSignature'), array(0,'DocumentRoot'), array(0,'DefaultDoc'), array(0,'GatewayInterface'),
                    array(0,'QueryString'), array(0,'RedirectStatus'), array(0,'RemoteAddr'), array(0,'RemotePort'),
                    array(0,'RequestMethod'), array(0,'ScriptFilename'), array(0,'ScriptName'), array(0,'ServerAddr'),
                    array(0,'ServerName'), array(0,'ServerPort'), array(0,'ServerProtocol'), array(0,'ServerSignature'),
                    array(0,'ServerSoftware'), array(0,'PhpSelf'),array(1,'mods'));
       foreach($qpv as $v)
          $$v[1] = $GLOBALS[$v[1]];
       $ModuleSignature.=" mod_{$name}/{$mod['version']}";
       foreach($qpv as $v)
          if($v[0] && $GLOBALS[$v[1]]!==$$v[1])
             echo 'Updated '. display_var($v[1],$$v[1]);
      echo display_var('RequestURI',$RequestURI);
      echo display_var('RquestHeaders',$RequestHeaders);
      if(!empty($logfile)) file_put_contents($logfile,$contents,FILE_APPEND);
      else echo $contents;

December 23rd, 2008, 11:20 am

Joined: December 22nd, 2008, 7:02 am
Posts: 20
Post QuickPHP Mods: Access Log
Module: Access Log
Version: 1.0
Last Updated: 2008-12-23

Okay, now that we got a good base of Mods for QuickPHP, I finally got around to doing a simple access log module. Although due to QuickPHP not having a post processing script. There is no way to get some variables, such as Status Code and Content Size.
Log Format Variables
  • h - User Host IP
  • t - Time
  • r - Request URI
Pretty simple, if u want to change the format u change one string:
$logformat ="h t r";

pretty straight forward :)

Also note, that acesslog works best when it preceeds all other Mods. this way u can see what the user initially requested.
remember to set $logfile to whereever u want yer log file to be.

But its very nice to be able to see, who when and where. So we only got three variables

File: /bin/mods/accesslog.php
   // Because this is a pre processor we dont have access to some post processing variables, namely STATUS code and Output Size
   // But it should still give u a good reference to who has accessed yer site.
   // Note: This shud proceed any Mod Rewrite modules (ie: httpdir & errors)
   $logformat ="h t r";
   $alv = array ('h'=>$RemoteAddr,'t'=>date('[d/M/Y:H:i:s O]'),'r'=>"\"$RequestURI\"");
   $alk = array_keys($alv);


December 24th, 2008, 4:31 pm
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB.