ryanbutler
04-18-2008, 02:46 PM
I have two PHP documents, one titled 11.9 and the other one random.php. In 11.9 I'm trying to call the random.php document and generate random greetings from a randomization script. However, I can't quite figure out how to call the function from 11.9 and make it execute in random.php.
Here's 11.9:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>11.9</title>
</head>
<body>
<a href="random.php?function=greet">My called link</a>
</body>
</html>
Here's random.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>11.9</title>
</head>
<body>
<?php
//store random greetings
switch($greet){
case 1:
$greet = 'Hello!';
break;
case 2:
$greet = 'Welcome!';
break;
case 3:
$greet = 'Greetings!';
break;
case 4:
$greet = 'Salutations!';
break;
case 5:
$greet = 'Good day!';
break;
case 6:
$greet = 'Yo!';
break;
}
echo $greet;
//set the seed for mtrand with the number of microseconds
//since the last full second of the clock
mt_srand((double)microtime() * 1000000);
//computes a random integer 0-4
$number=mt_rand(0,5);
echo $number;
?>
</body>
</html>
I don't think you can call a link directly from PHP per se. However, I thought perhaps you could call a link that passes a parameter to a function from there, is that correct? I'm not even sure I have the randomization part correct.
Any help or assistance would be greatly appreciated.
Here's 11.9:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>11.9</title>
</head>
<body>
<a href="random.php?function=greet">My called link</a>
</body>
</html>
Here's random.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>11.9</title>
</head>
<body>
<?php
//store random greetings
switch($greet){
case 1:
$greet = 'Hello!';
break;
case 2:
$greet = 'Welcome!';
break;
case 3:
$greet = 'Greetings!';
break;
case 4:
$greet = 'Salutations!';
break;
case 5:
$greet = 'Good day!';
break;
case 6:
$greet = 'Yo!';
break;
}
echo $greet;
//set the seed for mtrand with the number of microseconds
//since the last full second of the clock
mt_srand((double)microtime() * 1000000);
//computes a random integer 0-4
$number=mt_rand(0,5);
echo $number;
?>
</body>
</html>
I don't think you can call a link directly from PHP per se. However, I thought perhaps you could call a link that passes a parameter to a function from there, is that correct? I'm not even sure I have the randomization part correct.
Any help or assistance would be greatly appreciated.