Hi,
Just fooling around with fwrite and fread when i seem to have hit a wall.
Basically, what i am trying to do is, make an md5 hash of a number, write
that number to a file.
A bit later read the hash from that file and compare it to a number, if its
1, then print 1 , if 2 print 2...
I have tried 2 ways of doing this, with an "if" and with strcmp, its reading
and writing perfectly...only
not comparing....heres my code ( and yes, i got most of it from the manual)
:

<?php
$type=$_GET['type'];

if($type<4)
{

$filename = '/home/secure/public_html/testing/test.txt';
$somecontent = strtoupper(md5($type));

if (is_writable($filename)) {
  if (!$handle = fopen($filename, 'wb')) {
     echo "Cannot open file ($filename)";
     exit; }

  // Write $somecontent to our opened file.
  if (!fwrite($handle, $somecontent)) {
    echo "Cannot write to file ($filename)";
    exit;  }

   echo "Success, wrote ($somecontent) to file ($filename)";
   fclose($handle);
} else {  echo "The file $filename is not writable";}

}
else if($type==4){
$filename = "/home/secure/public_html/testing/test.txt";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);

/*****************************************
* All the above is working...the problem part is bleow *
******************************************/

if(strcmp($contents,md5("1"))==0)
 {echo "Yes, its 1<br>";}
else if(strcmp($contents,md5("2"))==0)
 {echo "Yes, its 2<br>";}
else if(strcmp($contents,md5("3"))==0)
 {echo "Yes, its 3<br>";}
else {echo "file is blank";}


/*if($contents==md5("1"))
 {echo "Yes, its 1<br>";}
else if($contents==md5("2"))
 {echo "Yes, its 2<br>";}
else if($contents==md5("3"))
 {echo "Yes, its 3<br>";}
else {echo "file is blank";}*/
echo $contents;
}

Both the above ways to compare the hash is failing....what am i doing wrong?

Thanks,
-Ryan
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to