How this website works internally

How this website works internally

This Website is powered by a little PHP script I wrote. It utilizes a very tiny flat file CMS: less than 20 lines of PHP code and less than 20 lines of HTML. Most stuff is done by PHP Markdown by Michel Fortin for formatting the page content.

No database system - just plain text files. Very fast and almost unbreakable.

The basic idea is:

  1. Let the apache web server redirect the request to this PHP script with options based on the request string after the domain without the trailing ".html" through .htaccess.

  2. The PHP script looks for an .md file with the requested name. This file contains in the first line the page title following standard markdown code.

  3. If it exists the "PHP Markdown" engine is feeded with its content or with the content on a predefined error page otherwise-.

  4. The result will be injected in the website template.


So in detail:


RewriteEngine On
# everything before .html becomes option value $1
RewriteRule ^(.*)\.html$ index.php?page=$1 [L]
# the predefined error page
ErrorDocument 404 index.php?page=error404

page title

## Header 2




$page = "";
$title = "";

if (!empty($_GET)) {
    $page = $_GET['page'] . ".md";
if (file_exists($page)) {
    // read all lines of file in array $data of lines
    $data = file($page);
    // the first element (line) is the title (excluding PHP_EOL)
    $title = array_splice($data,0,1)[0];
    // the remaining data is the content
    $text = implode(PHP_EOL,$data);
    // pass content through the Markdown parser
    $html = MarkdownExtra::defaultTransform($text);
else if ($page!=="") {
    header($_SERVER['SERVER_PROTOCOL']." 404 Not Found");
    $title = "Error 404: Not Found";
    $text = implode(PHP_EOL,array_splice(file(''),1));
    $html = MarkdownExtra::defaultTransform($text);

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?php echo $title; ?></title>
      echo $html;
    &copy; 2015 by Example




page title

Header 2


© 2015 by Example

You got the basic idea ...

Of course the actual website contains a bit more code e.g for error handling and syntax highlighting.