Jamesking56 Posted July 25, 2009 Share Posted July 25, 2009 I need to search for a string in ALL PHP files and in other folders too, in the actual code, How can I do this is PHP?Like this:1.php2.phpfolder1 - 1.php - folder2 -- 2.phpsearcher.phpHow can I search all PHP files for a certain code, and the script to tell me which file its in and where? Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted July 26, 2009 Share Posted July 26, 2009 Try to modify this script if you want (I put it together a while ago). Maybe change the base directory, and have it make sure the file is a .php one. This also searches the name of the file...Also, I would suggest you use sessions to some how require a password so people can't spam your server.It searches all of the sub folders and files for the query string: <?php$searchterm = $_SERVER['QUERY_STRING'] != '' ? $_SERVER['QUERY_STRING'] : 'default';$base_dir = $_SERVER['DOCUMENT_ROOT'];$dir = $base_dir.'/';$file = scandir($dir);$folders[0] = 'null';foreach($file as $key => $name) if(count($found) < 101 && $name != '.' && $name != '..') if(is_dir($dir.$name)) array_push($folders,$dir.$name); else if(strpos(file_get_contents($dir.$name),$searchterm) !== false || strpos($name,$searchterm) !== false) echo $dir.$name.' <- Found Search Term<br>';while(count($folders) > 1)foreach($folders as $key22 => $name22){ if($name22 != 'null' && $name22 != '') { $file = scandir($name22); foreach($file as $key => $name) if(count($found) < 101 && $name != '.' && $name != '..') if(is_dir($name22.'/'.$name)) array_push($folders,$name22.'/'.$name); else if(strpos(file_get_contents($name22.'/'.$name),$searchterm) !== false || strpos($name,$searchterm) !== false) echo $name22.'/'.$name.' <- Found Search Term<br>'; } unset($folders[$key22]);}?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.