sHTTPd.php is the main file which must be executed within a php(5) environment. It expects one parameter which defines the current working directory. In the most cases that directory should be the directory where sHTTPd.php exists.
php -f /home/user/sHTTPd/sHTTPd.php /home/user/sHTTPd
sHTTPd.conf is loaded at program start. Changes to this file will not be present during runtime. You will have to restart the server to make them effektive.
Listen2IP: (Default: 0)
The IP(v4) the server shall listen to.
Listen2Port: (Default: 8080)
The Port the server shall listen to.
AllowExternalRequests: (Default: 0)
Whether the server shall answer external requests or not. 0 for no, 1 for yes. When external requests are not allowed the server sends a 403 Forbidden response.
WebRoot: (Default: serv/)
The path to the data you want to deliver by the server. The path can be absolute or relative. When giving a relative path be sure that you have started sHTTPd.php with the correct working directory parameter.
AutoHeaders4PHPScripts: (Default: 1)
Whether the server shall send automatic (standard) http-headers when a php script is requested. 0 for no, 1 for yes. You want to deactivate this behavior if you want to generate own http-headers in your php script. Notice: When deactivated no headers are sent by default, you have to set up every header on your own (also e.g. "HTTP/1.1 200 OK"). Notice: This is also effective for html files.
This script decides how and what shall be replied to the client. It can answer with:
- 403 Forbidden if the request is external and not allowed.
- 404 Not Found if the requested file was not found within the web root.
- 200 OK if the requested file was found and executed without errors.
- or any headers you setup manually in your php-script.
Any other file than php-files (or html-files) will be delivered with a 200 OK and a Conent-Length header. The server does not deliver (differ) any MIME-types and does not set a header for that.
There are several variables set during the runtime of the server and during every handled request:
$GLOBALS['conf'] (set at program start)
This variable holds all directives and values from sHTTPd.conf in an associative array.
SHTTPD_ADDRESS (set at program start)
SHTTPD_PORT (set at program start)
SHTTPD_ROOT (set at program start)
SHTTPD_ROOT holds the working directory of the server. This is affected by the first paramater when starting the server.
$_SERVER['REQUEST_TIME'] (set at request)
An unix timestamp when the request came in.
$_SERVER['REQUEST_HEADERS'] (set at request)
An associative array holding each HTTP header from the request.
$_SERVER['REQUEST_METHOD'] (set at request)
$_SERVER['REQUEST_URI'] (set at request)
The requested file (and path). If no file was specified sHTTPd assumes "index.php" (auto-index).
$rip (set at request)
The client's IP(v4).
Just like expected:
Cookies are hold in an associative array in $_COOKIE.
GET variables are hold in an associative array in $_GET.
POST data is hold in an associative array in $_POST.
Notice: Cookies, GET and POST data are NOT url-decoded. You will have to do that on your own.
Notice: You cannot use the function-name "keep()" in your scripts since it is already registered.