Jump to content

if expression not acting as expected


oh_php_designer

Recommended Posts

so when doing the following:

$get_ignore_files = mysql_query("select file_name from ignore_files") or die(mysql_error());
$ignore_loopcounts=0;
while ($row = mysql_fetch_array($get_ignore_files)) 
    {	   		 
	   $ignore_file = $row['file_name'];
	   
	     if($ignore_loopcounts ==0)
		 {
		    $_SESSION['ignore_file_string'].= "$"."file_to_scan == '".$ignore_file."'";
		 }
		 else
		 {
		   $_SESSION['ignore_file_string'].= "||$"."file_to_scan == '".$ignore_file."'";
		 }
	     
		 $ignore_loopcounts=$ignore_loopcounts+1;
	}	

for $_session['ignore_files_string'  I get the results:  

$file_to_scan == '/home/a2222/public_html/test2.txt'  (file in my table)  this is expected...

 

when my if statement test it, it does not work

if (  $file_to_scan == $_SESSION['log_file']  || $file_to_scan == $_SESSION['monitor'] || $file_to_scan == $_SESSION['monitor.ini']  || $file_to_scan == $_SESSION['monitor_detected_file']
    || $file_to_scan == $_SESSION['root_path'].'/'.'class.phpmailer.php' || $file_to_scan == $_SESSION['root_path'].'/'.'class.smtp.php' 
does not work --> || $_SESSION['ignore_file_string']	
 but this does -->  //|| $file_to_scan == '/home/a2222/public_html/test2.txt'
						    
 )

if I echo out the session variable for ignore_file_string, it matches the line that works.  what is going on ????

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/294633-if-expression-not-acting-as-expected/
Share on other sites

if you are expecting php code that's been placed inside a variable to run, that's not how php works.

 

perhaps the following example will give you an idea how you might accomplish this - 

$files[] = $_SESSION['log_file'];
$files[] = $_SESSION['monitor'];
$files[] = $_SESSION['monitor.ini'];
$files[] = $_SESSION['monitor_detected_file'];
$files[] = $_SESSION['root_path'].'/'.'class.phpmailer.php';
$files[] = $_SESSION['root_path'].'/'.'class.smtp.php';
// add any other entries you want to include in the test here...

if ( in_array($file_to_scan,$files)) {

    // code to run if $file_to_scan matches any of the entries in the $files array

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.