Ajax software
Free javascripts
↑
Main Page
On a Windows machine, you can find the font files in the hidden
\Windows\Fonts
folder, or via
the Fonts applet that you can find in Control Panel. Create a folder named
fonts
under your
seophp
folder, and copy
comic.ttf
(or another font) to the
fonts
folder you’ve just created.
4.
Create
fortune_cookie.php
in the
seophp
folder, with this code:
<?php
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.”
);
// Member that will the generated image
var $_image_resource;
// 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);
}
}
// Set proper content type for GIF image
header(‘Content-type: image/gif’);
// Generate the GIF image
$f = new Fortunes();
$f->MakeFortune();
?>
5.
Load
http://seophp.example.com/fortune_cookie.php
. The result should look like
Figure 10-2.
6.
To be used as link bait, the fortune cookie needs to be easily placed in other pages. Assume that
one of your visitors has a page named
linkbait.html
, and that he or she wants to add your
fortune cookie to that page. Create a new file named
linkbait.html
in your
seophp
folder,
and type the following code. The highlighted piece of code is what you need to give your visi-
tors so that they can use your fortune cookie:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
<html>
<head>
215
Chapter 10: Link Bait
c10.qxd:c10 10:44 215
Ajax software
Free javascripts
→