cannot write file

Thread Solved

Join Date: Mar 2008
Posts: 70
Reputation: forzadraco is an unknown quantity at this point 
Solved Threads: 1
forzadraco forzadraco is offline Offline
Junior Poster in Training

cannot write file

 
0
  #1
Feb 12th, 2009
[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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: cannot write file

 
0
  #2
Feb 12th, 2009
  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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,521
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

Re: cannot write file

 
0
  #3
Feb 12th, 2009
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.
  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.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC