as you can see from my code below I have set a variable ($query) equal to the data posted from an outside form. Under that I tested the variable by echoing it, so the variable seems to be established correctly.
The problem is that near the bottom I'm trying to create another variable, called $str_to_find, where I want it set to output my original variable, $query. However, when I view the output, nothing shows up at all after the code processes this variable near the bottom of my code. I dont' understand why it wouldn't display output.
<?php
$query = $_POST['query'];
echo "$query";
find_files('.');
function find_files($seed) {
if(! is_dir($seed)) return false;
$files = array();
$dirs = array($seed);
while(NULL !== ($dir = array_pop($dirs)))
{
if($dh = opendir($dir))
{
while( false !== ($file = readdir($dh)))
{
if($file == '.' || $file == '..') continue;
$path = $dir . '/' . $file;
if(is_dir($path)) {
$dirs[] = $path;
}
else {
if(preg_match('/^.*\.(php[\d]?|js|txt)$/i', $path)) {
check_files($path);
}
}
}
closedir($dh);
}
}
}
function check_files($this_file) {
$str_to_find = $query;
if(!($content = file_get_contents($this_file))) {
echo("<p>Could not check $this_file</p>\n");
}
else {
if(stristr($content, $str_to_find)) {
echo("<p>$this_file -> contains $str_to_find</p>\n");
}
}
unset($content);
}
?>
UPDATED CODE
<?php
$query = $_POST['query'];
find_files('.');
function find_files($seed)
{
if(! is_dir($seed)) return false;
$files = array();
$dirs = array($seed);
while(NULL !== ($dir = array_pop($dirs)))
{
if($dh = opendir($dir))
{
while( false !== ($file = readdir($dh)))
{
if($file == '.' || $file == '..') continue;
$path = $dir . '/' . $file;
if(is_dir($path)) { $dirs[] = $path; }
else { if(preg_match('/^.*\.(php[\d]?|js|txt)$/i', $path)) { check_files($path); }}
}
closedir($dh);
}
}
}
function check_files($this_file)
{
$query = $_POST['query'];
$str_to_find = $query;
if(!($content = file_get_contents($this_file))) { echo("<p>Could not check $this_file</p>\n"); }
else { if(stristr($content, $str_to_find)) { echo("<p>$this_file -> contains
$str_to_find</p>\n"); }}
unset($content);
}
?>
globalor, better, pass it as an argument to the functionfunction check_files($this_file) { global $query; $str_to_find = $query;