This forum is in archive mode. You will not be able to post new content.

Author Topic: PHP search engine help!  (Read 1791 times)

0 Members and 1 Guest are viewing this topic.

Offline Phage

  • VIP
  • Overlord
  • *
  • Posts: 1280
  • Cookies: 120
    • View Profile
PHP search engine help!
« on: 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.

Code: [Select]
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:

Code: [Select]
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
« Last Edit: July 21, 2012, 01:51:49 AM by Narraz »
"Ruby devs do, in fact, get all the girls. No girl wants a python, but EVERY girl wants rubies" - connection

"It always takes longer than you expect, even when you take into account Hofstadter’s Law."

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: PHP search engine help!
« Reply #1 on: July 21, 2012, 02:17:15 AM »
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?
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline iTpHo3NiX

  • EZ's Pirate Captain
  • Administrator
  • Titan
  • *
  • Posts: 2920
  • Cookies: 328
    • View Profile
    • EvilZone
Re: PHP search engine help!
« Reply #2 on: July 21, 2012, 04:32:32 AM »
asdf
« Last Edit: February 13, 2013, 11:58:36 AM by DeepCopy »
[09:27] (+lenoch) iTpHo3NiX can even manipulate me to suck dick
[09:27] (+lenoch) oh no that's voluntary
[09:27] (+lenoch) sorry

Offline Phage

  • VIP
  • Overlord
  • *
  • Posts: 1280
  • Cookies: 120
    • View Profile
Re: PHP search engine help!
« Reply #3 on: July 21, 2012, 12:13:33 PM »
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?
"Ruby devs do, in fact, get all the girls. No girl wants a python, but EVERY girl wants rubies" - connection

"It always takes longer than you expect, even when you take into account Hofstadter’s Law."

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: PHP search engine help!
« Reply #4 on: July 21, 2012, 04:28:52 PM »
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.
« Last Edit: July 21, 2012, 04:29:31 PM by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Phage

  • VIP
  • Overlord
  • *
  • Posts: 1280
  • Cookies: 120
    • View Profile
Re: PHP search engine help!
« Reply #5 on: July 22, 2012, 10:01:48 AM »
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.
"Ruby devs do, in fact, get all the girls. No girl wants a python, but EVERY girl wants rubies" - connection

"It always takes longer than you expect, even when you take into account Hofstadter’s Law."

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: PHP search engine help!
« Reply #6 on: July 22, 2012, 04:42:58 PM »
Code: (php) [Select]
<?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 :)
« Last Edit: July 22, 2012, 04:43:19 PM by Factionwars »
~Factionwars

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.