943,731 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1038
  • PHP RSS
Feb 12th, 2009
0

cannot write file

Expand Post »
[code] target.php:

xas xjahs dajdh ajdhjas da d xxxx na dh ada hd

[code] main.php:
<?php
// removal malicious script by forzadraco

$filename="target.php";

$existfile=@fopen($filename,"w");

if($existfile){
echo "file berhasil dibaca \n\n";
}else{
echo "file gagal dibaca \n\n";
}


if( false == ($str=file_get_contents( $filename )))
echo "Could not read file.";
else
echo "File contents: ".htmlspecialchars($str);

$hsl=preg_replace("/xxxx/i","draco",$str);

echo "<hr />".htmlspecialchars($hsl);

fwrite($existfile,$hsl);
fclose($existfile);

?>

why is not work ? and why target.php become empty file..?

thanks
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
forzadraco is offline Offline
70 posts
since Mar 2008
Feb 12th, 2009
0

Re: cannot write file

php Syntax (Toggle Plain Text)
  1. <?php
  2. // removal malicious script by forzadraco
  3.  
  4. $filename="target.php";
  5.  
  6. $existfile=fopen($filename,"a+");
  7.  
  8. if($existfile){
  9. echo "file berhasil dibaca \n\n";
  10. }else{
  11. echo "file gagal dibaca \n\n";
  12. }
  13.  
  14.  
  15. if( false == ($str=file_get_contents( $filename )))
  16. echo "Could not read file.";
  17. else
  18. echo "File contents: ".htmlspecialchars($str);
  19.  
  20. $hsl=preg_replace("/xxxx/i","draco",$str);
  21.  
  22. echo "<hr />".htmlspecialchars($hsl);
  23.  
  24. fwrite($existfile,$hsl);
  25. fclose($existfile);
  26.  
  27. ?>
Check "mode" http://in2.php.net/manual/en/function.fopen.php . Mode "w" : Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 12th, 2009
0

Re: cannot write file

I have read the script and if you are using php5 then the following might be better with the functions file_get_contents and file_put_contents.
php Syntax (Toggle Plain Text)
  1. <?php
  2. // removal malicious script by forzadraco
  3.  
  4. $filename="target.php";
  5.  
  6. $existfile=file_get_contents($filename);
  7.  
  8. if($existfile){
  9. echo "file berhasil dibaca \n\n";
  10. }else{
  11. echo "file gagal dibaca \n\n";
  12. }
  13.  
  14.  
  15. if( false == ($str=file_get_contents( $filename ))) {
  16. echo "Could not read file.";
  17. } else {
  18. echo "File contents: ".htmlspecialchars($str);
  19. }
  20.  
  21. $hsl=preg_replace("/xxxx/i","draco",$str);
  22.  
  23. echo "<hr />".htmlspecialchars($hsl);
  24.  
  25. file_put_contents($hsl,$existfile);
  26.  
  27. ?>
Note: It's good to see you made an attempt at adding the opening code tags but next time try to add the closing code tags too.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Record with image upload script/ help?
Next Thread in PHP Forum Timeline: nl2br question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC