Jump to content

Simple write to file script


CloudConX

Recommended Posts

<?php

$filename = 'logfile.txt';

 

if (is_writable($filename)) {

 

  if (!$handle = fopen($filename, 'a')) {

        echo "Cannot open file ($filename)";

        exit;

  }

 

  if (fwrite($handle, $input) === FALSE) {

      echo "Cannot write to file ($filename)";

      exit;

  }

 

  echo "Success, wrote ($input) to file ($filename)";

 

  fclose($handle);

 

} else {

  echo "The file $filename is not writable";

}

?>

 

in the url I have http://www.site.com/logger.php?input='blahblah'

 

I get an output of "Success, wrote () to file (logfile.txt)";"

no matter what the variable I use (eg. logger.php?blah=blah) returns the same thing

 

This will not write the input to the text file... permissions set. Any guesses?

 

 

Link to comment
https://forums.phpfreaks.com/topic/75288-simple-write-to-file-script/
Share on other sites

Looks like you either need register globals to be "on" (not recommended) or to use the $_GET[] variables:

 

<?php
$filename = 'logfile.txt';

if (is_writable($filename)) {

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

   if (fwrite($handle, $_GET['input']) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }

   echo "Success, wrote ($_GET['input']) to file ($filename)";

   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
?>

Archived

This topic is now archived and is closed to further replies.

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