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
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";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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