Easter Eggs: What They Are and How to Create Them

An Easter egg is a hidden message or feature, completely unrelated to normal functionality, that developers put inside software, website, or game. Unlike viruses, worms, and trojans, Easter eggs are completely harmless. They are often used as a sort of signature of a programmer or as a joke. Sometimes they are written by personal initiative of a programmer and not a company request, and in those cases the company might take legal action against the developer. On the other hand, there are plenty of cases where a company, especially ones that specialize in game development, explicitly request several Easter eggs.

A Short History of the Easter Eggs

The term comes from the Anglo-Saxon tradition where parents, hide some eggs in their garden for Easter and then let their children find them. This type of work is often used in games where, for example, through a combination of keys or performing certain actions in a given order, you can access new levels or new powers.

For several years people, myself included, thought that the game Adventure released by Atari in 1979 was the first video game to containing an Easter egg. It wasn’t as amazing as you might think; it just displayed Warren Robinett (the name of the programmer). Although this myth is still alive, it seems that previous Easter eggs existed.

The number of Easter eggs contained in software and games, even the most famous ones, has increased over the last couple decades. The web offers a plethora of examples; companies like Mozilla, Oracle, and Google are just few who have put Easter eggs in their software.

  • Mozilla put an Easter egg in all versions of Firefox. To see it in action, type “about:mozilla” in the address bar and then press enter. Firefox displays a quote from the “Book of Mozilla” about the birth of Firefox.
  • Google created an Easter egg in Picasa. If you open the desktop software and then press Ctrl + Shift + Y, a toy bear image appears. Every time you press the key combination, another bear is displayed.
  • Skype, the famous VoIP software, has a simple but funny example. If you open the chat and then type “(drunk)” a hidden emoticon appears.
  • A Tetris game has been hidden in the uTorrent software. To see it, click the “Help” menu and then go to “About”. Press T key and the game will appear.
  • The OpenOffice suite has a lot of hidden games and other stuff. So many that they have a specific section on their website! If you want to play Tic-Tac-Toe in Calc, write “=GAME(A2:C4;”TicTacToe”)” into the A1 cell and then press enter.

Creating Your First Easter Egg

I’ll guide you in creating a simple Easter egg with PHP. We’ll create a search form, and if a user searches for my name (obviously you can change with your own) the page will show a nice message. This will be the Easter egg.

Create a PHP file with the following HTML code:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>My First Easter Egg!</title>
 </head>
 <body>
  <h1>My First Easter Egg!</h1>
  <h2>Search</h2>
  <form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
   <input type="text" name="searched-text" id="searched-text" placeholder="Search..." accesskey="s">
   <input type="submit" value="Search">
  </form>
 </body>
</html>

The form doesn’t have many elements; it only needs an input box where the user can type what she wants to search for and the submit button.

Try to use the form. As you’ll see, it does nothing but redirects the user to the same page, sending what was entered in the search field as a parameter. The business logic has not implemented yet, so don’t worry that nothing special happens.

The next step is to write the business logic. We need to analyze the request using the $_GET superglobal array to see its value. If the searched-text parameter isn’t empty, we’ll display what the user searched for, but in case she searched for my name, I’ll add the funny message “I know, I’m so cool!”.

The resultant code should look as follow.

<?php
if (! empty($_GET['searched-text'])) {
    echo "<h3>You searched for: " . htmlentities($_GET["searched-text"]) . "</h3>";
    // The comparison is case-insensitive
    if (strcasecmp($_GET["searched-text"], "Aurelio De Rosa") == 0) {
        echo "<p>I know, I'm so cool!</p>";
}

Now, when the user searches for my name she’ll see the following screen:

A Slightly More Complicated Example

As you’ve seen, the previous example is very simple. Now I’ll explain a sightly more complicated example. Imagine you have the form, but it’s not very professional to show the message the first time a user searches for your name. Maybe she’s just searching for some software you’ve written. What you can do is to show the funny message only if the user persists in searching repeatedly your name. Ultimately we need a counter and, for the sake of the example, I’ll display the message if the user searches for my name three consecutively times.

The first thing needed is to call session_start(), a function that creates a new session or resumes the current one. Then test if the Easter egg counter is set in the $_SESSION superglobal array; if not, we’ll set its value to zero. Every time the user searches for my name the counter is incremented by 1. In all the other cases, the counter is reset. The last case includes if the message has been displayed too.

The resulting source code is the following:

<?php
session_start();
if (!isset($_SESSION["easter-egg"])) {
    $_SESSION["easter-egg"] = 0;
}
?>
<html>
 <head>
  <meta charset="UTF-8">
  <title>My First Easter Egg!</title>
 </head>
 <body>
  <h1>My First Easter Egg!</h1>
  <h2>Search</h2>
  <form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
   <input type="text" name="searched-text" id="searched-text" placeholder="Search..." accesskey="s">
   <input type="submit" value="Search">
  </form>
<?php
if (!empty($_GET["searched-text"])) {
    echo "<h3>You searched for: " . htmlentities($_GET["searched-text"]) . "</h3>";
    // The comparison is case-insensitive
    if (strcasecmp($_GET["searched-text"], "Aurelio De Rosa") == 0) {
        $_SESSION["easter-egg"]++;
        if ($_SESSION["easter-egg"] == 3) {
            echo "<p>I know, I'm so cool!</p>";
            $_SESSION["easter-egg"] = 0;
        }
    }
    else {
        $_SESSION["easter-egg"] = 0;
    }
}
else {
    $_SESSION["easter-egg"] = 0;
}
?>
 </body>
</html>

Conclusions

I’ve shown you in this article how you can create a simple Easter egg. Easter eggs are a fun way to sign your software and to prove your paternity, Be careful though not to add one in your company software because the consequences could be undesirable. Now, every time you run a new program you’ll probably want search the Internet to see if it contains an Easter egg.

Image via Fotolia

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Patrick

    This isn’t really about how to create an easter egg, more a tutorial on how to do simple string comparison and use the basic features of sessions in PHP. An easter egg can be almost anything – they’re a way for a programmer to show their creativity. Given that, it’s futile to try to create a “guide” to making them. Explaining the concept is fine, reducing it to incredibly boring plain text output like this is sad and kinda defeats the point.

    • http://www.audero.it/ Aurelio De Rosa

      While I understand your point, it means that or I had to exclude an example and this would lead our readers to not have a minimal idea of what I was talking about or create a so complex example that a good part of our readers would not understand. However, if you feel that you need to show a better example, you can write an article atop of mine and publish it. We’re always looking for other authors that want to share their knowledge and thoughts.

    • http://www.damiengrass.com Damien

      It’s doing both. It’s demonstrating the use of string comparisons and sessions, in it’s simplest form, but it’s also demonstrating an Easter egg. It may be simple to you, I and many other people – but to people who are just starting to learn, this would be helpful. It’s demonstrating the basics of an Easter egg, a new developer can take this and build upon it, building it in such a way that would demonstrate their creativity.

      • Voitcus

        I’m not sure whether a novice PHP programmer should start with coding Easter Eggs…

  • http://www.codeconquest.com/ Charles @ CodeConquest.com

    I’ve just started learning how to make PHP forms so this article helped me quite a bit. Perhaps I’ll include an Easter egg in my next form!

    • http://www.audero.it/ Aurelio De Rosa

      I’m happy this article inspired you, but pay attention in using Easter eggs in software developed for work. Your boss might not appreciate it.

  • http://www.shotfocused.com cody dmd

    Cool Thing, thanks for sharing Aurelio !

  • http://www.surf-rite.com Thanks Aurelio

    Thanks for the example.I am a php/mysql novice,so I eat this stuff up and learn.

  • http://quran.2index.net Said Bakr

    Simple but useful article. It is the first time I know the definition of such tricks.

    • http://www.audero.it/ Aurelio De Rosa

      I’m glad this article has been informative.

  • Guus

    While this is a very simple way of showing what an Easter Egg is, there is something wrong, I feel…
    I quote: “if the user searches for my name three consecutively times.” and further on “Every time the user searches for my name the counter is incremented by 1. In all the other cases, the counter is reset. The last case includes if the message has been displayed too.”
    Consecutively searching for a name means: uninterrupted searching for a name, i.e. only that name, three times, time after time, no other search string in between.
    The code, I’m afraid, doesn’t quite do that, as it would allow one to search for your name, something else, your name, something else, your name, after which it would still show the Easter Egg…

    Just my two cents,
    Guus

    • http://www.audero.it/ Aurelio De Rosa

      You’re right. It was my intention but I forget the due else condition. Thank you for pointing it out, I’ve updated the code.

  • Aveesh Kumar

    Good job explaining what an easter egg is and an example using PHP. I just want to add that in programming for almost 20 years now, I have noticed 2 other conditions that seem to be what we (I) think of Easter Eggs:
    1 – Part of a program, usually standalone and on the desktop
    2 – Invoked by a hotkey/key combination

    The last time, I put an Easter Egg in was in Excel VBA code for a very large Balance/Sheet/Cash flow Forecasting program – invoked by Alt+Shift T, it would briefly display a couple flashing textboxes with names of my programing team!

    If I were to do in PHP, I would think I would do on a keystroke/DHTML showing a dialog/new window briefly….hmmm now how would I do that? :-)

  • John Pyle

    Shouldn’t you be posting the form, why the get method?

    • http://www.audero.it/ Aurelio De Rosa

      No. For search forms the normal behaviour is to use the get method so people can also share or bookmark the result. If you see, all the search engines use the GET method too.

  • http://www.sevenfiv.com Irshad

    I like this Article, i really understand this is written for the people who don’t know what anything and willing to start doing this, from this they can learn and do advance things.
    if anyone like Patrick know more, they can publish more advance article above this and it will be helpful to learn the next steps

  • rohit

    thanx for article…..

  • http://habeshawebsite.com habesha

    I love this site, and this is my first comment. I am very new to PHP, but I can not understand what in the world is the purpose of this: htmlspecialchars($_SERVER["PHP_SELF"]); The server can only post into the url it loads, so even a url puts malicious codes in the URL, it is hopless because, the URL the server will submit to is already pre-defined

    • http://www.audero.it/ Aurelio De Rosa

      Hi. It’s used for security reason. If you need more information, take a look here.

  • Carol Roberts

    When I was a courtroom artist in DC in the late 70’s, I used to draw extra famous figures into the jury box, like Lincoln, Martin Luther King, George Washington. I guess those were video easter eggs!

    I was encouraged by my boss at Origin Systems (game company) to sneak in whatever I could. I did. The Jane’s combat sims games I worked on have many silly things in them. I still do it when I can.

    • http://www.audero.it/ Aurelio De Rosa

      Thank you so much for sharing your experience.

  • Alex

    How can you make this work for the search form on a WordPress site?