2 Forum Posts by "DylanHolland"
Ok, so to put it shortly I have alot HTML pages generated on my website. In order to search through them I index it all to a txt file, and pull them according to words accociated with each link. I'm trying to randomly pull content, but my logic is flawed. I'm not so much asking as how to code it as how to go about it. I have this script, which does pull randomly but only from about the first 40 rows in the file and only pulls 3 and makes duplicate links in the random menu (there's supposed to be 10 random links:)
<?php
$filename = $_SERVER['DOCUMENT_ROOT'] . "/search/search.index.dat";
$file = fopen($filename, "r+");
$stream = fread($file, filesize($filename));
fclose( $file );
$search[0] = explode( "\n", $stream );
$tmp_ind = rand(0, sizeOf($stream));
for( $i = 0; $i < 10; $i++ )
{
foreach( $index as $key => $content )
{
$j=0;
foreach( $index as $name => $value )
{
if($content==$value)
{
$value = rand(0, sizeOf($stream));
}
}
if( $content == $tmp_ind )
{
$tmp_ind = rand(0, sizeOf($stream));
}
}
$index[$i] = $tmp_ind;
$search[1] = explode( "|", $search[0][$tmp_ind] );
$search[2] = str_replace($_SERVER['DOCUMENT_ROOT'],$_SERVER['HTTP_HOST'],$search[1][0]);
$search[3] = str_replace($_SERVER['DOCUMENT_ROOT'],"",$search[2]);
$search[4] = get_meta_tags("http://".$search[2]);
print "<li><a href=\"".$search[1][0]."\">".$search[4]["search"]."</a></li>\n<br />\n";
}
?>
P.S. the text file rows look like this:
doc/root/file/index.html|website|content
doc/root/file/books.html|book1|author|etc
and just to be more clear each file has a meta tag with its title in it, and thats how i'm pulling them
Ok, i'm trying to write a file viewer in php; and etwas going along quite well for a bit. Got too 100 lines and could run it through all the folders and view the files. Then, i noticed that after going up one directory it would simply not find another nested directory so I attempted to create a session to store an ever changing dir.
But now for some reason, the session itself will go up one directory and even with this test (which just changes the dir name to /kernel (actually /{$i} but for right now its hard coded to /kernel. It still won't go down into another directory. It should add /kernel everytime I click the link but it does it once and then won't add anymore to the dir.
Please someone give me an idea on how to solve this, my mind is drained and it seemed almost done last night!!!
shortened script (that does the samething but without links and file views (just dir):
session_start();
$directory = getcwd();
if( ( isset( $_GET["i"] ) ) && isset( $directory ) )
{
$_SESSION['new_dir'] = $directory ."/". $_GET['i'];
header("Location: ".$_SERVER['PHP_SELF']);
exit;
} else
{
if(isset( $directory ))
{
print str_replace($_SERVER['DOCUMENT_ROOT'],"",$directory) . "<br />\n";
$result = scandir($directory);
foreach( $result as $key => $content )
{
print $content ."<br />\n";
}
print "<a href=\"index.php?i=kernel\">kernel</a><hr />\n";
print (isset($_SESSION["new_dir"]))?$_SESSION['new_dir']:"";
} else { die("WHAT?"); }
}

