I setup a site that just has a picture on it. Whenever the page is refreshed a random image is chosen. I was using javascript to do this. But somebody on a different forum posted their PHP script and said I could use it. If I could get it to work it would make site adminstration a little easier. Here is the script..
<?
// Change the three variables below.
// Only change the text between the quotation marks (").
$yourSite = "http://whatever.com"; // Your website URL
$dirName = "images/"; // The directory in which you store your images.
$alt = "Back to My Site"; // Whatever text you wish to appear in your "alt" attribute (optional).
// Be sure not to change anything below this point
// other than the HTML (unless you know what you're doing).
if(!$refresh)
{
$refresh = "30";
}
function randomImage($dirname, $alt)
{
$dirhandle = opendir($dirname);
while (false !== ($file = readdir($dirhandle)))
{
if ($file != "." && $file != ".." && !@is_dir($file) )
{
$filelist[] = $file;
}
}
closedir($dirhandle);
srand((double)microtime()*1000000);
$picnum = @(0, sizeof($filelist) - 1);
$imageName = $dirname.$filelist[$picnum];
$imageSize = getimagesize($imageName);
$result = "<img class='border' src='".$imageName ."' ". $imageSize[3] ." alt='". $alt. "'>";
return $result;
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>whatever.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="refresh" content="<?=$refresh;?>">
</head>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle">
<a href="<?=$yourSite;?>"><?=randomImage($dirName, $alt)?></a><br>
<br>
Auto-Refresh Rate: <b><?=$refresh;?> seconds</b><br>
<a href="./random.php?refresh=30">30 seconds</a> | <a href="./random.php?refresh=45">45 seconds</a> | <a href="./random.php?refresh=60">60 seconds</a>
</td>
</tr>
</table>
</body>
</html>
I modified the top few lines like it says to. And since this is going to be used on a windows machine I changed to a \ at the end of the images folder. Whenever I try to access the site, I get...
Parse error: parse error, unexpected T_STRING in D:\weallwentmental\random.php on line 8
I don't know PHP coding at all. I talked to a couple people and they say the script works fine on apache servers. So it must be something with PHP on IIS. I downloaded the latest version of PHP and installed it. I'm assuming it's installed correctly since I'm getting error messages. But I don't know.
Any help would be greatly appreciated. Thanks.