My own server My Home page Sign Guestbook Read Guestbook
The Apache manual The PHP manual PHP examples (Core PHP Progr.) PHP examples (Pro. PHP Progr.) My own PHP exemples

PHP-test 9

Random quote generator


"But I've always thought--tests are a gift. And great tests are a great gift. To fail the test is a misfortune. But to refuse the test is to refuse the gift, and something worse, more irrevocable, than misfortune."
Cordelia's view when Aral is offered the Regency
(Lois McMaster Bujold, Shards of Honor)

The qoute text file has been "borrowed" from The Dendarii Nexus (http://www.dendarii.com), where it is also used to generate random quotes.

New quote: Click this link to get a new quote from Lois McMaster Bujold.

Ferengi: Click this link to get the "Ferengi Rules of Acquisition" instead.

View code: Click this link to see the code for this page.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/REC-html4/loose.dtd">
<HTML>
<HEAD>
  <TITLE>Random quote generator</TITLE>

<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">


  <META NAME="Author" CONTENT="Bo Johansson">
  <META NAME="Keywords" CONTENT="php, random quote generator, quotes">
  <META NAME="Description" CONTENT="PHP random quote generator">


<link REL="SHORTCUT ICON" href="../bj16html.ico">

<STYLE TYPE="text/css">
<!--

.tdimg TD IMG {display: block;}

//-->
</STYLE>


<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--

var jsNavBase = "../"

//-->
</SCRIPT>

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="../navbt/button_updwn.js">
<!--
//-->
</SCRIPT>


<?php

$navBase
= "../";

$altLang = "";    // no Swedish version

$actPage = 99;    // this page not in navbar

require("../navbt/nav_eng.php");

?>

</HEAD>

<BODY>

<?php

require("../navbt/nav_horz.php");

?>

<H1 ALIGN=CENTER>PHP-test 9</H1>

<H2 ALIGN=CENTER>Random quote generator</H2>

<HR>

<?php

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
*
*   The quotes are in the text files "9_quote.txt" and
*   "9ferengi.txt", and each of the individual quotes are
*   separated by newline characters
*
*   This version of the script by Bo Johansson 2002-05-10
*
*            Modified by Bo Johansson 2003-08-29
*
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

if( $_SERVER['QUERY_STRING'] == "ferengi" )
{
  
$quotes = file('9ferengi.txt');
}

else
  
$quotes = file('9_quote.txt');

if (!
$quotes)
{
  print(
'<H3><FONT COLOR="#FF0000">The quote generator is');
  print(
' temporarily out of service</FONT><H3>');
}

else
{
  
srand ((double) microtime() * 1000000);

  print(
$quotes[rand(0,count($quotes))] );
}

if( !isset(
$_ENV['QUERY_STRING']) )
{
  print(
"\n" . '<HR>' . "\n");

  print(
'The qoute text file has been &quot;borrowed&quot; ');
  print(
'from The Dendarii Nexus ' . "\n");
  print(
'(<A HREF="http://www.dendarii.com">http://www.dendarii.com</A>),');
  print(
"\n" . ' where it is also used to generate random quotes.');
}

?>

<HR>

<P>
<A HREF="9_quote.php"><B>New quote:</B></A> Click this
link to get a new quote from Lois McMaster Bujold.

<P><A HREF="9_quote.php?ferengi"><B>Ferengi:</B></A> Click this
link to get the &quot;Ferengi Rules of Acquisition&quot; instead.

<P><A HREF="9_quote.php?code"><B>View code:</B></A> Click this
link to see the code for this page.


<HR>


<?php

if( $_SERVER['QUERY_STRING'] == "code" )
{
  print(
'<TABLE ALIGN=CENTER BGCOLOR="#FFFFCC" WIDTH="95%">');
  print(
'<TR><TD>');

  
highlight_file("9_quote.php");

  print(
'</TD></TR></TABLE>');

  print(
'<HR>');

}

?>


<FONT SIZE="-2">Page created 2001-10-26, last changed

<?

print(date("Y-m-d H:i", getlastmod() ));

?>

</FONT>

<P>&copy;

<?

print(date("Y", getlastmod() ));

?>

Bo Johansson

</BODY>
</HTML>

Page created 2001-10-26, last changed 2003-08-30 10:26
This mirror page last changed 2009-12-04

© 2003 Bo Johansson