I am trying to make a script which changes the favicon at every refresh.
<?php
$dir = "img/icons/";
$files = array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$files[] = $file;
}
}
$icon = $files[rand(2,count($files)-1)];
echo "<LINK REL=\"shortcut icon\" HREF=\'img/icons/'.$icon."\">";
?>
This script gets every favicon from the /img/icons folder, and randomly selects one. The problem is that when I paste it in my HTML file, weird characters appear at the top of the page “; ?>.Can anyone fix my script ?
Here you can have a look at using PHP in HTML. Also your server should be properly configured for this. I always recommend
.phpto deal with PHP scripts.Hope this helps.