fake_rest_server – REST server in PHP

fake_rest_server” is a simple and easy-to-configure REST server made in PHP.

I made it just to create different REST servers very fast for testing purposes. It was made on 12th May 2016 (approximately).

It can be found on GitHub: https://github.com/jalbam/fake_rest_server

Configuring the server

To add new paths (routes) and methods, the developer just needs to create a new folder structure (folder and subfolders if needed) which represents the route and inside one file per method named [method_desired].php (for example, put.php).

To start developing your REST server, you will only need to download the files inside the src/ folder.

You may want to take a look at the src/_code/functions.php file (the engine will include it automatically) as it provides some basic but useful functions. There you can also add new functions or modify the existing ones.

If you want to add data, you can use the src/_code/data/data.php file (automatically included by the engine).

If you want to add configuration data, you can use the src/_code/config.php file (automatically included by the engine).

As the engine defines the USING_REST_SERVER constant, you can protect any of the files with the following line at the beginning:

<?php if (!defined("USING_REST_SERVER") || !USING_REST_SERVER) { return; } ?>

Note: this authorization code above is also defined in the AUTHORIZATION_CODE constant (inside the the src/_code/config.php file).


1) In the root folder (where the src/_code/ folder and the src/index.php file are placed), create a folder called myRESTService/.

2) Inside the myRESTService/ folder we have just created, create another folder called user/ and inside of it create two files: index.php and get.php.

3) Inside the myRESTService/user/index.php file, place the following code:

  //Users info (this could be in the "src/_code/config.php" file, but it is just an example):
  $usersData = Array
    //User IDs:
    "1" =>
        "name" => "John Doe",
        "favouriteFood" => "meat"
    "2" =>
        "name" => "Joan Alba Maldonado",
        "favouriteFood" => "pizza"
  //Gets the data needed which has been sent through the REST client:
  $userId = getVariable("id"); //"getVariable" and other functions available in the "src/_code/functions.php" file.

4) Inside the myRESTService/user/get.php file put the following code:

  if ($userId === "") { echo "No id sent!"; }
  else if (array_key_exists($userId, $usersData))
    echo $usersData[$userId]["name"] . " likes eating " . $usersData[$userId]["favouriteFood"];
  else { echo "User cannot be found! (id=" . $userId . ")"; }

5) With this, we will have our REST server configured with the myRESTService/user/ route, accepting the GET method with the id parameter. This example can be found in the example_easy/ folder.

Testing the server

If you do not have a REST client, the server can be tested on any web browser by adding the debug=1 parameter to the URL as well as the method parameter with the method desired (not needed if the method is GET), as for example: http://localhost/fake_rest_server/src/index.php/route_1/subroute?method=post&debug=1&username=Joan

Following the example above, you can use a web browser to visit the following links:

http://localhost/route_to_the_REST_server/index.php/myRESTService/user/?method=get&debug=1&id=1 (it should show “John Doe likes eating meat”)

http://localhost/route_to_the_REST_server/index.php/myRESTService/user/?method=get&debug=1&id=2 (it should show “Joan Alba Maldonado likes eating pizza”)

http://localhost/route_to_the_REST_server/index.php/myRESTService/user/?method=get&debug=1&id=3 (it should show “User cannot be found! (id=3)”)

http://localhost/route_to_the_REST_server/index.php/myRESTService/user/?method=get&debug=1 (it should show “No id sent!”)

Note that the “/” character at the end of the route is optional.

Final comments

It is very easy to extend using PHP language. The project already includes some examples with routes, methods, functions and data as user accounts, etc. as examples (in both the example/ and the example_easy/ folder) but they can be deleted.

The only really-needed code is located in the src/ folder. Inside of it, the route_1/ folder and all of its content can also be deleted since it is just an example.


This project can be used, reproduced, distributed and modified freely for any non-commercial purposes but always keeping the author’s name and copyright clauses. Other than that, just use this project as you wish but never sell it!

Super Queue – queue and lottery viral game in PHP and JavaScript (November 2014)

I made this game for a Chinese software company whose final client was a chain of jewelry stores that wanted a Weixin (aka WeChat) game to promote themselves by giving the players some prizes and coupons just during a week (to celebrate the Chinese Single’s day, the 11th of November). Weixin (WeChat) is the most used instant messaging client for mobile devices in China, made by Tencent (the same company that also owns QQ). It was finished on 7th November 2014 (approximately).


The graphics are made by 乔安 (Qiao An) and Chinese translation is done by 董双丽 (Dong Shuangli). The development took almost one month.

The game consists of two levels. In the first level, you are waiting in a queue and your mission is to jump the queue until you can enter the door. Once you enter through the door, the second level consists in waiting for a partner of the opposite gender (it can be either a real player or a fake one if the game is configured to use fake players or the admin force it) and, when you get a partner, then each of you have to spin a roulette wheel with zodiac symbols and both will win a prize if you both get the same zodiac symbol. If you get a different symbol, you get a discount coupon instead.

It is a viral game because players have to share the game to others in order to jump the queue they are waiting in. Every time someone registers through your invitation, you will jump two places. But others will also be able to jump and move in front of you so it becomes a kind of fight.

Players do not need to have the game open all the time. So they can close the game and open it again later whenever they want to. If any progress has been made or any thing new has happened, the game will show it.

There is a maximum number of people per queue, so the game creates a “new world” with a new queue every time a person joins the game for the first time if all other queues are full. The game also fills the queue with fake people in order to increase level difficulty and to avoid looking empty. All of that is configurable through variables.

The way to log in, prizes, maximum people per queue, chances to win, and many other things can be configured through the configuration file.

The game already includes Chinese and English languages. There is also a localization file that allows to translate the game into many more languages easily. The game will try to detect automatically the user’s language.

The company wanted to run the game just for a week. During this week, the game was a complete success and had more than 50,000 players. All prizes were given out.

The game was running on Weixin (WeChat) and uses some of its functions, but it can be configured without effort to be used in any other app or platform (as for example in QQ, Facebook or any web browser with JavaScript and CSS enabled).

There is a debug mode which can be accessed through a password. That debug mode shows useful information about the game in real time and it also provides an admin control panel (similar to a God mode panel) with many options to cheat, control other players, etc.

It also includes an overload test page to check server limits.

This game was made using technologies as HTML, CSS / CSS 3, JavaScript, JSON, XHR (AJAX), PHP, mySQL, RPC (Remote Procedure Call), OpenID, OAuth, Weixin API (WeChat API) / WeixinJSBridge, etc.

You can try the game by yourself just creating the database needed (a SQL file with the required tables is included) and editing the configuration file to use that database. Basically, you just need a web server that supports PHP and mySQL.

It can be found on GitHub: https://github.com/jalbam/super_queue

La villa del seis – horror adventure game in PHP and DHTML (September 2006)

“La villa del seis” (aka “La villa del 6”) is an open source adventure game written in PHP, HTML, CSS and JavaScript.


This game was made in late 2006 and uses the engine of Yasmina’s Quest that I made before, modified and improved. It was made together with Yasminan Llaveria del Castillo and some of the photos used were taken by Esteban Villegas Gallego.

Official languages are Spanish and Catalan.

It has become quite famous on the Internet, with thousands and thousands of downloads and online players. It was even mentioned in at least one well-known Spanish magazine called “Año/Cero” in an article titled “La ruta de los pueblos condenados” written by José Manuel Serrano Cueto and published in January 2007 (on paper as well as on-line).

Since this has the Yasmina’s Quest engine but improved, some people has chosen the code of this game to create their adventure instead of using the Yasmina’s Quest code. As well as Yasmina’s Quest, the game can be played either as a point-and-click adventure or as a text adventure and it can run in any kind of web browser. JavaScript and CSS are useful but not really necessary. Images are not necessary either, allowing the game to be played in a text-based web browser as Lynx or Links.

This game has been tested under BeOS, Linux, NetBSD, OpenBSD, FreeBSD, Windows, Mac OS X, QNX, BlackBerry Tablet OS, Android, iOS and others. In its homepage you can see some screenshots with the game running on many different platforms such as Nintendo DS, Sony PSP, Sega Dreamcast and Pocket PC.

Recently (27 September 2018), a new package using php-webkit was added so it can be played offline on Windows XP with SP2 (Service Pack 2) and newer (including Windows 10). Just download the la_villa_del_seis_php-webkit_win32.zip or the la_villa_del_seis_php-webkit_win32.7z file. The la_villa_del_seis_php-webkit_win32_installer.exe file also provides an installer for the same package. Porting the same package to other operating systems and platforms should not be too difficult. For some older Windows versions (older than Windows XP with SP2), the la_villa_del_seis_on_server2go.zip file (la_vila_del_sis_on_server2go.zip file in Catalan) provides an older package which uses Server2Go.

Play online in Spanish: http://lavilladel6.tuxfamily.org/lavilladel6_spanish/

Play online in Spanish (mirror): http://www.dhtmlgames.com/lavilladel6/lavilladel6_spanish/

Play online in Catalan: http://lavilladel6.tuxfamily.org/lavilladel6_catalan/

Play online in Catalan (mirror): http://www.dhtmlgames.com/lavilladel6/lavilladel6_catalan/

Official web site: http://lavilladel6.tuxfamily.org/ (mirror at http://www.dhtmlgames.com/lavilladel6/).

It can also be found on GitHub: https://github.com/jalbam/lavilladel6

La carta más alta – card game in PHP and HTML (December 2005)

“La carta más alta” is an open source card game made with PHP, HTML and a little bit of CSS. It was created on 19th December 2005 (approximately).


It is in Spanish language and will work in any web browser, even without CSS support.

The game is minimalist and it doesn’t use any image at all but only text created with pure HTML and tables. So you will be able to play it in a text-based browser too, such as Links and Lynx.

This cross-platform and cross-browser game has been tested under BeOS, Linux, NetBSD, OpenBSD, FreeBSD, Windows, Mac OS X, QNX, BlackBerry Tablet OS, Android, iOS and others.

Play online: http://lcma.tuxfamily.org/lcma_spanish/

Play online (mirror): http://www.dhtmlgames.com/lcma/lcma_spanish/

Official web site: http://lcma.tuxfamily.org/ (mirror at http://www.dhtmlgames.com/lcma/).

It can also be found on GitHub: https://github.com/jalbam/lcma

Yasmina’s Quest – adventure game engine in PHP and DHTML (November 2005)

“Yasmina’s Quest” is an open source adventure game engine that comes with one adventure game as example (in Spanish) totally written using PHP, HTML, CSS and JavaScript. It was created on 17th November 2005 (approximately).


The games created with this engine can be played either as a point-and-click adventure (using mouse, pointer or your finger) or as a text adventure (using keyboard or any other text input method) and they are totally cross-browser and cross-platform.

Although it uses JavaScript in order to improve user interface, it is not mandatory and it works with any web browser without JavaScript support. Similarly, CSS is an advantage but not actually necessary. Even images are not necessary!

The characteristics of this engine are unique, letting developers create adventures that work in all web browsers and taking advantage of JavaScript and CSS to improve the user experience only if it is available. You will be able to play the game even in text-based web browsers such as Links and Lynx.

So far, I don’t know any other engine that works in all web browsers which let users play the same adventure in both modes, point-and-click adventure and text adventure.

It has been tested under BeOS, Linux, NetBSD, OpenBSD, FreeBSD, Windows, Mac OS X, QNX, BlackBerry Tablet OS, Android, iOS and others.

This engine has been used by some other people to create their own adventure.

Play online: http://yquest.tuxfamily.org/yq_spanish/

Play online (mirror): http://www.dhtmlgames.com/yquest/yq_spanish/

Official web site: http://yquest.tuxfamily.org/ (mirror at http://www.dhtmlgames.com/yquest/).

It can also be found on GitHub: https://github.com/jalbam/yquest