Fortune Cookies For Websites

Ever wonder how people get those groovy little fortune cookies on their website?

In this HOW TO, I’m gonna explain, in terms a computer-newbie using WINDOWS can understand:

  1. A little foreword and overview.
  2. A brief history of fortune, a “game” for older linux/unix/*nix systems.
  3. How to set up fortune cookies on your webpage, sort of like the one on the top of foothillsnerd.com
  4. Advice for and/or against some of the various other solutions
  5. A step-by-step guide for editing your WordPress file to do a self-installed fortune cookie php script
  6. Where to find some fortune cookie databases
  7. How to make your own fortune databases
  8. Links to lots of original resources of quality material that helped me set this up.

Don’t sweat it, it’s really simple!

1.  First, a foreword and shameless plug

I use 1&1 Internet Hosting. I like it.  A lot.  I’m sick of crappy and overpriced hosts, and I am happy to plug it with my afiliate signup link.  You can get a domain name AND page hosting for as little as 5$ (or less for the entry level packages) a month a domain.  And, unlike a lot of the near-priced competitors, the tech support (so far!) can fix your screwups, and they answer the phone without putting you on hold forever…and I can understand them (as opposed to some previous hosts)  I really REALLY am happy with their hosting which is the reason I affiliate with them[ www.1and1.com/?k_id=19063844,] is to sort of steer any business possible away from all the crappy domain hosts out there.   Even if you don’t use the affiliate link, 1&1 rocks and I recommend it!

2.   History of Fortune Cookie

Fortune is an old originally unix program written in the early 80s that displays essentially a short quip, blurb, or quote over the console to the person operating the computer.  Fortune has been ported to graphical versions and a whole bunch of operating systems (KDE, Gnome, etc.)

Freeware or Non Costing Downloads

Download: Windows fortune Cookie Program, © 1998 Tim Johnson
Download Amiga fortune Cookie Program v 1.0.8, R2, © 2001 Kalle Räisänen
Linux Users:  Use package manager if you don’t already have it.  It’s under the Games category.

Fortune is essentially a virtual fortune cookie using a database of delimited phrases, and a data file generated by strfile program.  Wikipedia has a great write up on it located here.

3.-6.  How to Install Fortune Cookies

There are lots of niche sites that have widgets, applets, java, and inframes to install their fortune cookie.  The caveat is that this provides links to their sites which helps increase their pageranks, and a lot of time these sites only exist to transfer this pagerank through strong links over to pages with less-than-enviable ambitions.  I’m usually a bit leery of free applets especially when I don’t know what’s justifying the cost, so I opt for the see-the-source-do-it-yourself when possible, even if I don’t understand everything, it’s just a healthier practice for online stuff.  Which brings me to the approach I elected for.

Henrik Aasted Sorensen wrote a beautiful PHP script/port of fortune and a great walkthrough of how to install the script on a php-compatible domain site (so pretty much any decent host and not craphosts like geocities+)  It’s a tight little script that isn’t resource hungry, and works nearly “straight outta the box” meaning other than a few little aspects, it’s very easy to understand it all.  His site is located here.

The easiest way to install this is to follow either the guide on Henrik’s website, or to follow the following three steps:

  1. Upload a copy of fortune.php to your domain server into your php directory (or the directory of the page you want to call it from)
  2. Copy in the following lines of code to wherever you want.  For example, on foothillsnerd.com (a wordpress installation) I went into wordpress’  SITE ADMIN–>DESIGN–>THEME EDITOR–>
  3. Then I clicked over on templates for header.php, and modified the following line from:

<?php bloginfo(’description’); ?>

TO

<?php
require(”fortune.php”);
$f = new Fortune;
echo $f->quoteFromDir(”dat/”);
?>
<!– <?php bloginfo(’description’); ?> –>

And voila.  A fortune cookie is installed….ALMOST!

You’ll still need to create a data directory and list it.  I use the default example directory of “dat”, however if you want to put your fortune cookie data files in the same directory as your php script, then just change the

echo $f->quoteFromDir(”dat/”); to echo $f->quoteFromDir(”/”);

AND, upload two fortune cookie files (the text and the data file).  Just to test it out, here’s a NIV book of Proverbs fortune cookie data file and entry list. And here’s a one-liners data file and entry list.

7.  How to Make Your Own Fortune Cookie Database

Coming Soon.

8.  Unfinished, Coming Soon also, but lots of links scattered throughout the blurb so far.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.