I have a very weird problem. On my website i have a script that takes random pages and displays them on the homepage. It works without a problem on its own but when i have it included in the homepage using
include('webmaster fav.php');
i get this error: Warning: Cannot use a scalar value as an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 18
and this error: Warning: array_unique() [function.array-unique]: The argument should be an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 20
and this error: Warning: array_unique() [function.array-unique]: The argument should be an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 21
and this error: Warning: Cannot use a scalar value as an array in /mnt/w0210/d28/s25/b02a8bb2/www/webmaster fav.php on line 23
I am kindof new to php but i think its a good script and it works without errors when it isn't included on the homepage it works. what could be the problem?
heres the code:
<?php
$directory = "/mnt/w0210/d28/s25/b02a8bb2/www/data/";
//the list of pages i want to be random on the site
$directory = (!strstr($directory,"*") || $directory =="./" ) ? $directory."*" : $directory;
//Checks if the wildcard operator is present, and if not it adds it by default at the end;
$files = glob($directory);
//Yes, it was that easy to get all the files;
$size=sizeof($files);
for($i=0;$i<sizeof($files) ; $i++){
//Loop through the files and adds to array;
$fp = fopen($files[$i],"r");
$contents[$i]=fgets($fp,999);
fclose($fp);
}
for($x=0;$x<15;$x++){
$numb[$x]=rand(1, sizeof($files));
}
$x=count($numb)-count(array_unique($numb));
$num = array_unique ($numb);
for($q=0;$x<15;$x++){
$numb[$x]=rand(1, sizeof($files));
}
//$imploded = implode(" ", $contents); //get rid of spaces
//$newcontent=explode("~", $imploded); // sort into chucks so i can display the data.
for($i=0;$i<15; $i++){
$number=$num[$i];
if($contents[$number]==""||$contents[$number]==" "||$contents[$number]==null){
}
else{
echo "<li>";
$replacedcontent=str_replace(' ', '-',$contents[$number]);
echo "<br/><a href='games/$replacedcontent'>";
$newrcontent=str_replace('-', ' ',$replacedcontent);
echo "<img src='$newrcontent.jpg' border='2'></img>";
echo "<br/>$newrcontent</a></li>";
}
}
?>
i copied and pasted it from many sites examples so thats why some comments are weird... but basically it gets all the data files. reads the title and puts them in an array, then chooses some random ones and puts them in with their image so they can be displayed on the homepage.