Posted: . At: 8:27 PM. This was 12 years ago. Post ID: 2939
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.
Sponsored
This code is on my https://securitronlinux.com/linux/ page. It shows a random image and a random webpage link.
<?php
$time = strftime(“%A %d %B %Y. %r – %Z”);
srand(time(NULL));
$day = rand() % 6;
$string = sprintf(“<font size=\”2pt\”><p>Welcome to my website.</p>\n”);
$links = array(“BejArray” => array(“0” => “perl_code.php”, “1” => “psx_doom.php”,
“2” => “cgi_code.php”, “3” => “doom_wadfiles.php”,
“4” => “my_linux_system_2.php”, “5” => “linux_configs.php”,
“6” => “my_linux_system.php”
));
echo $string;
switch($day) {
case 0:
$string2 = “Perl CGI Code”;
break;
case 1:
$string2 = “PSX Doom goodness”;
break;
case 2:
$string2 = “Misc programming code”;
break;
case 3:
$string2 = “My Doom wadfiles”;
break;
case 4:
$string2 = “My Linux system tips part 2”;
break;
case 5:
$string2 = “My Linux configuration tips”;
break;
case 6:
$string2 = “My Linux system tips part 1”;
break;
default:
$string2 = “Take pot luck”;
}
printf(“<p>Random page: <a href=%s>%s</a>.</p>\n”, $links[“BejArray”][$day], $string2);
printf(“<p>Welcome to my GNU/Linux pages. Server time is: %s.</p></font>”, $time);
echo “<img src=\”maps/00$day.png\” width=\”320\” height=\”200\” alt=\”Random Doom screenshot.\” style=\”float:right;padding: 8px\”>”;
?> |
<?php
$time = strftime(“%A %d %B %Y. %r – %Z”);
srand(time(NULL));
$day = rand() % 6;
$string = sprintf(“<font size=\”2pt\”><p>Welcome to my website.</p>\n”);
$links = array(“BejArray” => array(“0” => “perl_code.php”, “1” => “psx_doom.php”,
“2” => “cgi_code.php”, “3” => “doom_wadfiles.php”,
“4” => “my_linux_system_2.php”, “5” => “linux_configs.php”,
“6” => “my_linux_system.php”
));
echo $string;
switch($day) {
case 0:
$string2 = “Perl CGI Code”;
break;
case 1:
$string2 = “PSX Doom goodness”;
break;
case 2:
$string2 = “Misc programming code”;
break;
case 3:
$string2 = “My Doom wadfiles”;
break;
case 4:
$string2 = “My Linux system tips part 2”;
break;
case 5:
$string2 = “My Linux configuration tips”;
break;
case 6:
$string2 = “My Linux system tips part 1”;
break;
default:
$string2 = “Take pot luck”;
}
printf(“<p>Random page: <a href=%s>%s</a>.</p>\n”, $links[“BejArray”][$day], $string2);
printf(“<p>Welcome to my GNU/Linux pages. Server time is: %s.</p></font>”, $time);
echo “<img src=\”maps/00$day.png\” width=\”320\” height=\”200\” alt=\”Random Doom screenshot.\” style=\”float:right;padding: 8px\”>”;
?>
This is a good way to use the switch statement to deal with code appropriately depending on the value of a variable. This is very useful in programming.
Interesting, probably apply some of this code in my blog.