EvilZone
Programming and Scripting => Web Oriented Coding => : Phage July 21, 2012, 01:51:06 AM
-
Ok so i have recently created this website. I have tried to implement a PHP search engine, but it doesn't seem to work.
When i'm searching I get this error.
set_time_limit("600"); $keyword=trim($_POST["keyword"]); if($keyword==""){ echo"Please enter your keyword"; exit; } function listFiles($dir,$keyword,&$array){ $handle=opendir($dir); while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."){ if(is_dir("$dir/$file")){ listFiles("$dir/$file",$keyword,$array); } else{ $data=fread(fopen("$dir/$file","r"),filesize("$dir/$file")); if(eregi("]+)>(.+)",$data,$b)){ $body=strip_tags($b["2"]); } else{ $body=strip_tags($data); } if($file!="search.php"){ if(eregi("$keyword",$body)){ if(eregi("",$data,$m)){ $title=$m["1"]; } else{ $title="no title"; } $array[]="$dir/$file $title"; } } } } } } $array=array(); listFiles(".","$keyword",$array); foreach($array as $value){ list($filedir,$title)=split("[ ]",$value,"2"); echo "$title "." \n"; } ?>
The php code i have used is:
set_time_limit("600");
$keyword=trim($_POST["keyword"]);
if($keyword==""){
echo"Please enter your keyword";
exit; }
function listFiles($dir,$keyword,&$array){
$handle=opendir($dir);
while(false!==($file=readdir($handle))){
if($file!="."&&$file!=".."){
if(is_dir("$dir/$file")){
listFiles("$dir/$file",$keyword,$array);
}
else{
$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));
if(eregi("<body([^>]+)>(.+)</body>",$data,$b)){
$body=strip_tags($b["2"]);
}
else{
$body=strip_tags($data);
} if($file!="search.php"){
if(eregi("$keyword",$body)){
if(eregi("<title>(.+)</title>",$data,$m)){
$title=$m["1"];
}
else{
$title="no title";
}
$array[]="$dir/$file $title";
}
}
}
}
}
}
$array=array();
listFiles(".","$keyword",$array);
foreach($array as $value){
list($filedir,$title)=split("[ ]",$value,"2");
echo "$title "."
\n";
} ?>
I really hope some of you can help me.
Regards
Narraz
-
There is no error here? Just your PHP code in one line. Did you copy-paste the wrong text or something? Perhaps you forgot to start with <?php in your code?
-
asdf
-
Hmm i have found a solution on that problem i have to ad a @ before the "fread". But now when i'm searching i just get the website name three times. Can some you tell me why?
-
I am not sure how to help you here, you havent described any spesific problem and your first post makes no sense.
Also your code is horribly formated and you should use [ code = php ] (without spaces) in your code tags to make things easier to read.
-
Sry for my bad english and code. Well it wasn't me who coded it, i found it on the web, i was in a hurry and found it easy to use. Well the new problem is that, when i'm searching it just displays the name of the website on a blank page. I can't figure out how to solve the problem.
-
<?php
set_time_limit("600");
$keyword = trim($_POST["keyword"]);
if($keyword == ""){
echo"Please enter your keyword";
exit;
}
function listFiles($dir,$keyword,&$array){
$handle=opendir($dir);
while(false!==($file=readdir($handle))){
if($file!="."&&$file!=".."){
if(is_dir("$dir/$file")){
listFiles("$dir/$file",$keyword,$array);
}
else{
$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));
if(eregi("<body([^>]+)>(.+)</body>",$data,$b)){
$body=strip_tags($b["2"]);
}
else{
$body=strip_tags($data);
}
if($file!="search.php"){
if(eregi("$keyword",$body)){
if(eregi("<title>(.+)</title>",$data,$m)){
$title=$m["1"];
}
else{
$title="no title";
}
$array[]="$dir/$file $title";
}
}
}
}
}
}
$array=array();
listFiles(".","$keyword",$array);
foreach($array as $value){
list($filedir,$title)=split("[ ]",$value,"2");
echo "$title "."
\n";
} ?>
As you can see, recode it :)