
QuickPHP Mod Documentation
Starting Version 1.4.0, QuickPHP supports using PHP scripts to implement extensions / mods (à la Apache modules such as mod_rewrite, mod_headers etc.).
QuickPHP calls
QuickPHP_ReqMod.php (in the same folder as QuickPHP.exe) and passes the following variables to the script each time it processes a request. This enables the mods to modify the variables to implement functions such as mod_rewrite.
If QuickPHP_ReqMod.php file does not exist, QuickPHP simply works as before. This mod feature is for
advanced users only.
Note that some of the superglobals listed here are not available in every versions of QuickPHP. For example, $ExtraReplyHeaders is only available from v1.8.0 and above. It is therefore recommended that you always upgrade to the latest version.Variables available to the script:$DebugLog - Boolean - R/W - Default = trueThis flag set to true allows QuickPHP to save the output from executing QuickPHP_ReqMod.php to
QuickPHP_ReqMod_DebugLog.txt (same folder as QuickPHP.exe).
This allows you to output message to the log file via Echo, Print, etc. This also saves warning and error output messages from the PHP engine (e.g. Syntax errors in script).
$DebugLogFileName - String - R/W - Default = "QuickPHP_ReqMod_Log.txt"Logs will be saved to this file after mods have run. Requires $DebugLog to be enabled.
$RequestURI - String - R/WRead from this variable to find out the URI being requested by the client.
Set this to any URI you wish to redirect the request to (e.g. for implementing mod_rewrite).
$RequestHeaders - String - R/WContains the request headers sent from the client.
The request headers are delimited by '\r\n' (return and line feed characters).
To add an arbitary header, simply append a new line to this variable and terminate it with '\r\n'.
There is no limit to the number of headers you can add.
Hint: Parse this string into an array to conveniently add or remove headers and then reconstruct the string at the end.$ExtraReplyHeaders - String - R/WCan be used to send additional headers to the client. QuickPHP grabs this string and appends it to the end of the original reply header before sending it to the client.
The reply headers need to be delimited by '\r\n' (return and line feed characters).
To add an arbitary header, simply append a new line to this variable and terminate it with '\r\n'.
There is no limit to the number of headers you can add.
Hint: You can use this to do cache-control for non-PHP mime types (e.g. no-cache).$UniqueID - String - R/WContains a unique ID for the current request.
If you wish to generate your own UniqueID in place of the default, change this value.
$ModuleSignature - String - R/WEach module should append to this string to indicate its effects on the server.
e.g. ' mod_bwlimited/1.4' (Note the space before the name of the module).
Naming convention - '[space]<module name>/<version>'
$_QUICKPHP_SCRATCHPAD_<x>, <x> == 0 to 99 - String - R/WThese scratch pads are also accessible from your actual script, so they can be used to pass values from mods.
$DocumentRoot - String - RHolds the current DocumentRoot folder of this server.
$DefaultDoc - String - RHolds the filename of the default document of this server.
The following are variables similar to $_SERVER['x'].
Some of these values will be updated to reflect the altered $RequestURI (if it is altered) after the execution of the script.
$GatewayInterface - String - R
$QueryString - String - R
$RedirectStatus - String - R
$RemoteAddr - String - R
$RemotePort - String - R
$RequestMethod - String - R
$ScriptFilename - String - R
$ScriptName - String - R
$ServerAddr - String - R
$ServerName - String - R
$ServerPort - String - R
$ServerProtocol - String - R
$ServerSignature - String - R
$ServerSoftware - String - R
$PhpSelf - String - R
*** R - Read-only. They can be changed in the script but will not affect the way server processes the request.
*** R/W - Read-write. Can be changed and will affect the server.
Notes:It is recommended that you only include external PHP files from QuickPHP_ReqMod.php.
For example, for mod_rewrite, you could create a file called mod_rewrite.php, and include that in QuickPHP_ReqMod.php.
The QuickPHP_ReqMod.php file could end up calling several mods. In which case, it becomes a convenient place to enable / disable specific mods.
Example:
Code:
include("mod_rewrite.php");
include("mod_log_referer.php");
include("mod_spelling.php");
// Disabled mods. Uncomment to enable.
//include("mod_unique_id.php");
Mod Writing Conventions:In order to have all the mods working cohesively, the following superglobals usage conventions need to be adhered to closely.
- Superglobals are required to be left in a valid state at exit point of a mod.
- If a mod depends on the result of another mod, it is up to the user to include them in the right order.
- Always keep in mind that multiple mods can run in one request. Therefore, if you are assigning a string to a superglobal, make sure you use the append operator (e.g. $ExtraReplyHeader .= "Cache-Control: no-cache\r\n").
Getting Started:Get started with this - it simply prints out all the available variables into QuickPHP_ReqMod_DebugLog.txt. Create the following file and save it as QuickPHP_ReqMod.php (put it in the same folder as QuickPHP.exe). Request a page from QuickPHP (either PHP or HTML) and then look for QuickPHP_ReqMod_DebugLog.txt in QuickPHP.exe's folder.
Code:
<?php
$DebugLog = true;
Echo $DebugLogFileName."\r\n";
Echo $RequestURI."\r\n";
Echo $DocumentRoot."\r\n";
Echo $DefaultDoc."\r\n";
Echo $GatewayInterface."\r\n";
Echo $RequestHeaders."\r\n";
Echo $QueryString."\r\n";
Echo $RedirectStatus."\r\n";
Echo $RemoteAddr."\r\n";
Echo $RemotePort."\r\n";
Echo $RequestMethod."\r\n";
Echo $ScriptFilename."\r\n";
Echo $ScriptName."\r\n";
Echo $ServerAddr."\r\n";
Echo $ServerName."\r\n";
Echo $ServerPort."\r\n";
Echo $ServerProtocol."\r\n";
Echo $ServerSignature."\r\n";
Echo $ServerSoftware."\r\n";
Echo $UniqueID."\r\n";
Echo $PhpSelf."\r\n";
Echo $ModuleSignature."\r\n";
$ModuleSignature .= " mod_helloworld/0.1";
?>
See some mod examples under the thread titled
QuickPHP Mods (contributed by Laffin).
Feel free to post your own mods to share with the community.