Jump to content

if expression not acting as expected


oh_php_designer
Go to solution Solved by mac_gyver,

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
Share on other sites

  • Solution

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

}
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.