Above you see the method in action. rand(3,18) is an imitation of the role playing “3d6” (throw 3 sixsided dices). The random generator will give a value between 3 and 18. If you read the rules of Microlite 84 it’s easy to add more character properties.
In this case we’ll save the character data in a cookie in the client browser. However a cookie can only store a string. PHP can convert an array to a string:
Now we can save the data in a cookie via setcookie:
Here is a very short introduction to the principles of PHP. PHP is an acronym for “hypertext preprocessor”. PHP is a serverside language. We use PHP in order to prepare webpages, react to user input – and (on the third semester) to interact with databases.
Many Open Source CMSs use a combination of Apache, PHP and MySQL as an “engine”.
How to write PHP code
A php file is made in a manner similar to a HTML file. You create a file and give it the surname .php. So a file name sample could be:
Variables, Strings and numbers
$a = 10; // a number $b = “Hello World”; // a string $c = “Ho, ho, hooo!”; // yes it’s another string $d = “Santa Claus, says: “; // xmas is near $combinedStrings = $d . $c; // Santa Claus, says: Ho, ho, hooo!
$e = NULL; // no value set
$f = true; // or false ?>
A variable is defined via the $ character. In the sample code above you can see several variables.
A string starts and ends with a quotation mark as ” or ‘. If you need quotation marks inside a string they should be nested like this: