JavaScript Editor Ajax software     Free javascripts 



Main Page

The basic idea is very simple. You need to tell your visitors that if they paste the following code into their
HTML pages, they get a free fortune cookie:
<a href=”http://seophp.example.com”>
<img src=”http://seophp.example.com/fortune_cookie.php” border=”0”>
</a>
<br />Get your free
<a href=”http://seophp.example.com”>cookies at Cookie Ogre’s Warehouse</a>.
What’s interesting about this code is that it not only delivers the fortune cookie, but it also includes a link
to your web site (and the tool, so others may get fortunes). A small amount of users may remove the link,
but a significant amount will leave the link around the image. You’re providing your visitor with a free
service, in exchange for some publicity.
The code of the fortune cookie generator itself is simple. It simply takes a random text from an array, and
displays it over the cookie image contained in
fortune_cookie.gif
. If you had more entries, it would
make more sense to use a database, but for simplicity’s sake you store the possible fortune phrases into
an array:
class Fortunes
{
// Array with possible fortune predictions
var $_fortunes = array(
“Jaimie Sirovich will become your\r\nfavorite author.”,
“You will recommend this book to\r\nall your friends.”,
“Tomorrow you will make \r\nyour first million.”,
“You will read AJAX and PHP: \r\nBuilding Responsive Web Applications.”
);
The code that adds the text over the .gif image template is very simple as well. You used the
image-
createfromgif
,
imagettftext
, and
imagegif
functions of the GD2 library to generate and output
the fortune cookie image:
// Generate fortune cookie image
function MakeFortune()
{
$text = $this->_fortunes[rand(0, sizeof($this->_fortunes) - 1)];
$this->_image_resource = imagecreatefromgif(‘images/fortune_cookie.gif’);
imagettftext($this->_image_resource, 9, 0, 135, 64,
imagecolorallocate($this->_image_resource, 0, 0, 0),
‘fonts/comic.ttf’, $text);
imagegif($this->_image_resource);
}
Keep in mind that this is just one hypothetical example of link bait. Because we cannot possibly assist
readers with all of their ideas for link bait, we will suggest that if you do have a great idea, but cannot
implement it yourself, that you can use a service like eLance (
http://www.elance.com/
), which can
assist you in finding a freelance programmer. For simple projects this can be very effective.
217
Chapter 10: Link Bait
c10.qxd:c10 10:44 217


JavaScript Editor Ajax software     Free javascripts