can anyone make me a simple script to write text to a log file on server...

SleepieGirl

Regular Member
Joined
Mar 7, 2009
Messages
439
Reaction score
294
http://myservername.com/myscript.php?password="blah"&text="blah blah blah blah"

so then on my server ill have log.txt with "blah blah blah blah" inside of it?
 
Code:
<?php

$pass = $_GET['password'];
$text = $_GET['text'];

if($pass = "blah")
{
$file = fopen("log.txt","w"); 
echo fwrite($file,$text) . " bytes written.";
fclose($file);
}
else
{
echo "Incorrect password!";
}

?>

That should do it.
Just create log.txt file before using it.
 
Last edited:
lincher's solution is excellent, but here's a shorter version with no need to create log.txt beforehand and more extensive error-checking.

Code:
<?php

isset($_GET['pass'])    or die('you need a password');
$_GET['pass'] == 'blah' or die('wrong password');
isset($_GET['text'])    or die('you need to specify text');

file_put_contents('log.txt', $_GET['text']);

?>
 
And one more addition:
file_put_contents() will overwrite your file without the proper flags set.
So if you want to log continuously and keep the logged text, use:

PHP:
<?php
file_put_contents('log.txt', $_GET['text'], FILE_APPEND);
?>
 
If you need something more specific, you can contact me on skype : byte-x
Wont cost you anything :)
 
Back
Top