Wednesday, January 23, 2013

How to Make a Simple Game Site using PHP – Step 2

Let's start off with my frustration motivation. Today, I spent over 4 hours trying to install different arcade scripts (the biggest problem i have is that my server does not have the most current PHP version). I gave up and decided to get back to my simple game site using PHP.
Today, I will be installing the necessary files on MathGames.us. I could go into the whole seo behind math games, but i won't right now. If you read step 1, you know that i recommended for you to start collecting games and images. And uniformly naming them. I did not do that, so i will be quickly downloading 5 games, from my most popular math games site HoodaMath.com, as well as 5 images from there. Feel free to take some as well at http://hoodamath.com/gamesforyoursite/ I downloaded 5 swfs and images and renamed the files to match my style. For example i renamed pixies2.swf to Pixies_2.jpg and i renamed mathfind.jpg to Math_Find.jpg Now i will upload the flash folder and the images folder to my server. Each folder filled with their respective files. Now I will create and upload a simple database file called database.php the code will look like this: <?php $game = array( "Pixies_2", "Dublox", "Briker_2", "Math_Find", "Line_Bounder" ); ?> At this point you should have in your public_html: a flash folder, images folder, and database.php file Now I will demonstrate how to make your first game page. I will use Math Find as my example. I will create a file called Math_Find.php and put it in the public_html folder, with the following code inside.
<?php
$title = str_replace("_"," ",str_replace(".php","",str_replace("/","",$_SERVER["PHP_SELF"])));
echo "<html><body><table><tr><td width='810'>";
echo "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='800' height='600' />
<param name='movie' value='flash/";
echo         str_replace(" ","_", $title);
echo ".swf' />
<param name='quality' value='high' />
<embed src='flash/";
echo         str_replace(" ","_", $title);
echo ".swf' quality='high' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='800' height='600'></embed>";
echo "</td></tr></table></body></html>";
?>
<?php $title = str_replace("_"," ",str_replace(".php","",str_replace("/","",$_SERVER["PHP_SELF"]))); echo "<html><body><table><tr><td width='810'>"; echo "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='800' height='600' />            <param name='movie' value='flash/";            echo         str_replace(" ","_", $title); echo ".swf' />            <param name='quality' value='high' />            <embed src='flash/";            echo         str_replace(" ","_", $title); echo ".swf' quality='high' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='800' height='600'></embed>"; echo "</td></tr></table></body></html>"; ?> If you copy the Math_Find.php file and name each copy after each game you uploaded you will have several working pages of your games. I hope this tutorial got you on your way. WARNING: don't make too many games pages, because in tutorial 3, I'm going to demonstrate how to add a header, footer, etc. As well as making it easy to make changes to all of your files at once. By changing code in one center file. Please COMMENT, so I know that anyone is reading these tutorials.

No comments:

Post a Comment