We use cookies in order to save information about or from the user input. If you compare my Firefox and Chrome browsers they will format the Microlite roleplaying web page according to random values, dates and saved input. Computergames use random values in stead of dice. First the character is saved in an associative array.
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.
The cookie
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:
$toCookie=serialize($character);
Now we can save the data in a cookie via setcookie:
find the file gmail.phps and copy the file
paste it and rename to gmail.php
Edit the file and add your user details. For the sake of the test let the recipient be yourself.
If you fire off the file and get a mail then it works.
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:
myFile.php
The file can contain other forms of code and tags such as JavaScript, CSS or HTML. In the file the php code is nested between a <? and ends with a ?>.
Variables, Strings and numbers
<?php
$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:
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘xxxx_mmd_eal_dk’);
/** MySQL database username */
define(‘DB_USER’, ‘xxxx.mmd.eal.dk’);
/** MySQL database password */
define(‘DB_PASSWORD’, ‘*******’); // password hidden here 😉
/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);
Har netop konfigureret en LAMP server på et virtuelt Debiansystem i Mac OS X i virtualbox. Gnome skrivebordsmiljøet var for tungt; men LXDE fungerer fint. Jeg regner med at skrive koden i Pico (Nano), MC (Midnight Commander) og Bluefish.
Multimusen.dk will set a few cookies from Doubleclick, Google and the Social Media plugins they ay set some cookies. Some of my pages use APIs - such as YouTube, LinkedIn, Google Fonts, Google Maps, Mapbox, Spotify, Jetpack, Twitter, Facebook &c.. Such plugins may set the odd cookie.