Jump to content


Photo

Comparing two variables


  • Please log in to reply
4 replies to this topic

#1 Grande

Grande
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 March 2006 - 02:50 PM

[!--sizeo:2--][span style=\"font-size:10pt;line-height:100%\"][!--/sizeo--]
<html>
<head> 
<?php

$test1="exploit.rules";
$test2="exploit.rules";
$lines = file("./snortconf.txt");
$count = count($lines);
$i = 0;

?>
</head>
<body>
<form name ="snort" method="get" action="<?=$_SERVER['PHP_SELF']?>">

<?php
if(isset($_REQUEST['btnsubmit'])) { 
      //echo "entered submit request";
      
      if(isset($_REQUEST['chk2'])) {
          //echo "entered chkbox request";
          $rule = $_REQUEST['chk2']." ";
          
          while($i<$count){
              //echo $lines[$i]."<br>";
              //echo "<br>Dit staat ier juist voor de if functie<br>";
              
              if(ereg("^include",$lines[$i])){
                  //echo "jet gezien dat nen include is<br>";
                  //$breaker = explode("/",$lines[$i]);
                  //echo "<br>----------<br>";
                  //echo "\"".$breaker[1]."\"<br>"
                $breaker2 = str_replace("include \$RULE_PATH/","",$lines[$i]);
                //echo "\"".$breaker2."\"";
                  
                  
                  //echo "\"".$rule."\"";
                  //echo "<br>----------<br>";    
                  if ($rule==$breaker2) {
                      echo "TIS WERE GELUKT";
                  }
              }
              
          $i++;
          }
      }
}

echo "<input type='checkbox' name='chk2' value='".$test1."'>";
?>
<input type="submit" name="btnsubmit" value="Disable">
</form>
</body>
</html>
[!--sizec--][/span][!--/sizec--]



This is my code above.
I read a sentence that begins with include from a txt file(snortconf.txt) . Then I seperate the sentence and keep the last part of it with str_replace(). An other value, the value from a checkbox is submitted to its own page and the value is used for a Comparation with the value from the txt file.

When I echo both the values between quotes, so invisible spaces are revealed if they're there, they are
exactly the same. However, in the last if-loop where I compare $rule with $breaker2 I get false.
How is this possible ????? I have no clue.

snortconf.txt contains this:
TEST
TEST
TESTNUMMERDRIE
include $RULE_PATH/exploit.rules
TESTJE

A little help would be great.

PS: the comments are test-echo's, so I can see where the script goes and where it doesn't go, etc. So don't mind the language of the comments...

Thx
Grande

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 March 2006 - 02:59 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]When I echo both the values between quotes, so invisible spaces are revealed if they're there, they are
exactly the same.[/quote]
No, if you just do an "echo $var" to the screen the web browser will compress two or more adjacent spaces into one. In order to really see all the spaces either surround the variables with the '<pre></pre>' tags or replace all spaces with the special space "&nbsp;".

I would compare the trimmed values.

Ken

#3 Grande

Grande
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 March 2006 - 03:03 PM

[!--quoteo(post=357305:date=Mar 22 2006, 03:59 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 22 2006, 03:59 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
No, if you just do an "echo $var" to the screen the web browser will compress two or more adjacent spaces into one. In order to really see all the spaces either surround the variables with the '<pre></pre>' tags or replace all spaces with the special space "&nbsp;".

I would compare the trimmed values.

Ken
[/quote]


so this doesn't do the trick :
echo "\"".$breaker2."\"";


#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 March 2006 - 03:41 PM

No.

Run this script to see the differences:
<?php
$str1 = ' this string has many spaces at the end          ';
$str2 = ' this string has many spaces at the end ';
echo '"' . $str1.'"<br>';
echo '"' . $str2.'"<br>';
echo '<hr>';
if ($str1 == $str2) echo 'The strings are equal<br>';
else echo 'The strings are not equal<br>';
echo '<hr>';
echo '<pre>"' . $str1 . '"'."\n";
echo '"' . $str2 . '"</pre>';
echo '<hr>';
if (trim($str1) == trim($str2)) echo 'The trimmed strings are equal<br>';
else echo 'The trimmed strings are not equal<br>';
echo '<hr>';
echo '<pre>"' . trim($str1) . '"'."\n";
echo '"' . trim($str2) . '"</pre>';
?>

Ken

#5 Grande

Grande
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 March 2006 - 03:54 PM


Awesome,
You helped me solve a problem I was working on for two days in five minutes (or less ;) )
Thank you very much
appreesh !

Grande





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users