Monday, December 13, 2010

8Ball Magic Script using PHP script

Installation instructions for 8-Ball

The file and edit template.html to suit your needs.
Where you want the form to appear in the web page, insert
the string %%FORM%% and where you want the answer to be
displayed, insert the string %%ANSWER%%.

Open 8ball.php and set the $template variable to the name
of your template HTML file, if different from the default "template.html." Edit the $answers array, if you like, to
specify your own custom responses.

Upload the script and template HTML file to your web
server in ASCII mode. Point your web browser to the
8ball.php file in order to use the 8ball.

#########################################################

[Usage]

There are several ways to use this script. You can make
the templates full standalone pages and just link to the
8ball.php from your website, or you can make the templates
as tables and use a PHP <? include() ?> statement to make
the script a integral part of an existing webpage.

Template.html

<body bgcolor="#99CCCC">
<h3 align="center"><font color="#993300">SharemyPHP<font color="#993300">
Presents<br>
Magic 8-Ball!</font></h3>
<table width="90%" border="0" align="center" bgcolor="#000000" cellpadding="0" cellspacing="1">
<tr>
<td>
<table width="100%" border="0" bgcolor="#FFFFFF">
<tr>
<td>
<p align="left"><font size="2" face="Verdana, Arial">Welcome to the
Magic 8-Ball! It can answer any question that's on your mind. Think
of a good question and type it into the form below, then submit
the form to hear the wise oracle speak!</font></p>
<p align="center"><font face="Verdana, Arial" size="2">%%FORM%%</font></p>
<p align="center"><font size="2" face="Verdana, Arial" color="#3333CC"><b>%%ANSWER%%</b></font></p>
</td>
</tr>
</table>
</td>
</tr>
</table>

8ball.php

<?php
#########################################################
# 8-Ball #
#########################################################
# #
# This script was created by: #
# #
# PHPSelect Web Development Division. #
# This script and all included modules, lists or #
# images, documentation are copyright 2002 #
# #
# Purchasers are granted rights to use this script #
# on any site they own. There is no individual site #
# license needed per site. #
# #
# Any copying, distribution, modification with #
# intent to distribute as new code will result #
# in immediate loss of your rights to use this #
# program as well as possible legal action. #
# #
# This and many other fine scripts are available at #
# the above website or by emailing the authors at #
# #
#########################################################
#8ball.php #
# #
#This script will answer user-submitted questions in #
#the style of the "Magic 8-Ball." You can set your own #
#answers, as well as the output attributes. #
#########################################################

#Set the following configuration options:

#$answers is an array containing all possible responses
#the 8-ball will give.

$answers = array("Heck no!", "Not bloody likely.", "The possibilities look good...", "How should I know?", "Maybe.", "The answer looks hazy...", "Are you crazy? OF COURSE!", "Naaah.", "Anything's possible!", "I tend to doubt it.", "For sure!!");

#$template is the template file the script will use to
#format the output. This should be an HTML file with the
#appropriate tokens placed where you'd like the
#corresponding values to appear. See the INSTALL.txt file
#for more information.

$template = "template1.html";

#########################################################
#Editing below is not required. #
#########################################################

#load the template file
if(!$output = file($template))
die("Couldn't open the template file ($template). Please check and make sure that this file is where it's supposed to be.");
$output = implode("\n", $output);

#build output for %%FORM%%
$formoutput = "<form method=\"POST\" action=\"$_SERVER[PHP_SELF]\"><input type=\"hidden\" name=\"posted\" value=1><input type=\"text\" name=\"question\"><br><input type=\"submit\" value=\"Ask\"></form>";

#Answer a question if one was posted
if($_POST[posted]){
srand((double)microtime() * 1000000);
$answeroutput = $_POST[question] ? $answers[rand(0, (sizeof($answers)-1))] : "I can only answer if you ask a question!";
}
else
$answeroutput = "";

#replace tokens

$output = str_replace("%%FORM%%", $formoutput, $output);
$output = str_replace("%%ANSWER%%", $answeroutput, $output);

echo $output;

?>

By PHP with No comments

0 comments:

Post a Comment

    • Popular
    • Categories
    • Archives