<html>
<head>
<title>Factorial Ting</title>
</head>
<body>
<?php
if ((isset($_GET["n"])) || (isset($_GET["x"]))){
$factorial=0;
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
if(isset($_GET["n"])){
if (is_numeric($_GET["n"])){
$factorial=($_GET["n"]*(($_GET["n"]+1)/2));
}else{
echo("non-numeric input detected");
}
}else if (isset($_GET["x"])){
if (is_numeric($_GET["x"])){
for ($i=1; $i<=$_GET["x"]; $i++){
$factorial+=$i;
}
}else{
echo("non-numeric input detected!");
}
}
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo("The factorial of ".$_GET["x"]." is: ".$factorial." This answer was retrieved in: $totaltime seconds<br />");
echo("<a href=\"./factorial.php\">Find another factorial </a>");
}
else{
?>
Enter a number and the factorial of that number will be displayed
<form action="#" method="GET">
<input name="n" type="text" />
<input type="submit" value="Go!" />
</form>
Enter a number here for a different method of getting the factorial of a number. This method should take a lot longer.<br />
<strong>NOTE! For extremely large numbers, this may be incredibly slow!</strong>
<form action="#" method="GET">
<input name="x" type="text" />
<input type="submit" value="Go!" />
</form>
<?php
}
?>
</body>
</html>