Jump to content

Script works on its own page but broken when included in another.


maxyme

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.