Trivial local notes with PHP

June 10, 2023 - Reading time: 2 minutes

Post notes to you local network server.

Here is the PHP and other files needed.

Do not put this on the internet!

note.html

Form to post a note.

<form action="note.php" method="post">
<p>
<input type="text" name="name" size="40"/>
</p>
<p>
<textarea cols="80" name="message" rows="20"></textarea>
</p>
<p>
<input type="submit" value="Post note" /></form>
</p>
</form>

notes.html

File to which notes will be appended to. Make sure the server can write to this file.

<body>
<h1>Notes:</h1>

note.php

Script that will write the note.

<?php
$file = dirname(__FILE__).'/notes.html';
$name=$_POST['name'];
$message=$_POST['message'];
$entry = '<hr/><p><h3>'.date('Y-m-d H:i:s').'</h3><h4>'.$name.'</h4><pre>'.$message.'</pre></p>'.PHP_EOL;
$ret = file_put_contents($file, $entry, FILE_APPEND | LOCK_EX);
header('Location: ./notes.html');
//var_dump($entry);
//var_dump($ret);
//var_dump($file);
?>

Mastodon