Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryMiscellaneous

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Simple Online Notepad

An online notepad can be quite useful. I know. I use one for my browser home page.

Think of something and type it in. It's right there when it's needed.

(Note: Auto-Save Notepad is another option. It has minimum text formatting and uses an editable div instead of a textarea field.)

The notepad presented in this article can be accessed by you with any of your browsers or smart phones. The page is password protected. And the notepad page may be set as your browser's home page (which I do).

The notepad software is PHP and is located on your server.

The data is stored in a plain text file, not MySQL, and is protected from unauthorized access by browsers and robots. The protection comes from:

  1. The name of the file being .php, causing the server to process it before sending it to the browser/robot.

  2. The first line of the data file being <?php exit; ?> to immediately cause an exit and deliver nothing to the browser/robot.

Interested?

Here is the PHP file to upload to your server. (Customization notes follow.)

<?php
/* 
   Simple Online Notepad
   Version 1.0
   November 28, 2011

   Will Bontrager Software, LLC
   https://www.willmaster.com/
   Copyright 2011 Will Bontrager Software, LLC

   This software is provided "AS IS," without 
   any warranty of any kind, without even any 
   implied warranty such as merchantability 
   or fitness for a particular purpose.
   Will Bontrager Software, LLC grants 
   you a royalty free license to use or 
   modify this software provided this 
   notice appears on all copies. 
*/

######################
## Begin customization

# A password for the notepad page.

$Password = "password";

# A login cookie name.

$CookieName = "notepad";

# How many days the cookie shall last (decimal number is OK).
# Specify 0 to delete cookie when browser closes.

$DaysCookieLasts = 1.5;

# The subdirectory name for the notepad content. (May need 777 permissions.)

$NotepadDirectory = "notepad";

## End customization
####################

$needLogin = true;
$file = './' . trim($NotepadDirectory) . '/notepadcontent.php';
if( isset($_COOKIE[$CookieName]) ) { $needLogin = false; }
if( count($_POST) ) { Fix_POST(); }
if( isset($_POST['pw']) and $_POST['pw'] == trim($Password) )
{
   $DaysCookieLasts = floatval($DaysCookieLasts);
   $expire = $DaysCookieLasts > 0 ? ( time() + intval($DaysCookieLasts * 24 * 60 * 60) ) : 0;
   if( $expire ) { setcookie($CookieName,'1',$expire); }
   else { setcookie($CookieName,'1'); }
   $needLogin = false;
}
if( ! $needLogin and isset($_POST['notepad']) )
{
   $firstline = '<'.'?php exit; ?'.">\r\n";
   $f = fopen($file,'w');
   fwrite($f,$firstline.$_POST['notepad']);
   fclose($f);
}
function Fix_POST()
{
   if( isset($_POST['submitter']) ) { unset($_POST['submitter']); }
   foreach( $_POST as $k => $v )
   {
      if( is_array($_POST[$k]) )
      {
         foreach( $_POST[$k] as $kk => $vv )
         {
            $_POST[$k][$kk] = trim(stripslashes($vv));
         }
      }
      else { $_POST[$k] = trim(stripslashes($v)); }
   }
} # function Fix_POST()
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>Simple Online Notepad</title>
</head>
<body>
<form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>">


<?php if($needLogin): ?>

<h3>Log In</h3>
<input type="password" name="pw" style="width:300px;"><br>
<input style="width:300px; text-align:left; padding-left:15px;" value="Log In" name="submit" type="submit">


<?php else: ?>

<h3 style="margin-bottom: 3px;">Simple Notepad</h3>
<!-- On the next line, specify width and height you prefer for the textarea box. -->
<textarea name="notepad" style="width:600px; height:300px; padding:6px; border:1px solid black;"><?php
$f = @fopen($file,'r');
if( $f )
{
   $line = '';
   fgets($f,20);
   while( ($line = fgets($f,16384)) !== false ) { echo $line; }
   fclose($f);
}
?></textarea><br>
<input style="width:300px; text-align:left; padding-left:15px;" value="Update Notepad" name="submit" type="submit">

<?php endif; ?>


</form>
</body>
</html>

Simple Online Notepad Customizations

The customization area is about 20 lines from the top of the file. Four things can be customized.

  1. Password. Specify the password between the quotation marks. The password may be composed of any keyboard characters and may contain spaces within it. If the password itself contains quotation marks, the quotation marks need to be escaped with a preceding backslash. Example: \"

  2. Cookie name. The cookie name is specified between the quotation marks. It needs to start with a letter and may contain lettes, numbers, and underscore characters.

  3. Days cookie lasts. The number of days the cookie shall last is specified. A decimal number may be used. If the cookie shall be deleted when the browser closes, specify 0 (zero).

  4. Notepad directory. Between the quotation marks, specify the subdirectory where the notepad file will be written. That would be a subdirectory from where Simple Online Notepad is installed. The subdirectory may need 777 permissions, but try the default 755 first.

In the web page area of the script, the dimensions of the textarea box form field can be changed. The box where notes are displayed and typed into.

At about line 83, you'll see an HTML comment tag like this:
<!-- On the next line, specify width and height you prefer for the textarea box. -->

On the line below the HTML comment tag, you'll see the textarea field tag. The tag contains an inline CSS style that specifies, among other things, the width and the height of the textarea box.

The width and height may be changed.

Implementing Simple Online Notepad

The above PHP script can be named anything you wish, so long as the file name ends with .php

In the following examples, I'll assume you named it "mynotepad.php".

Create a subdirectory for the online notepad software or use a subdirectory already existing. In the following examples, I'll assume you are using a subdirectory named "onlinenotepad".

Upload the notepad script into "onlinenotepad".

In step 4 of the above list of customizations, you specified a subdirectory where the notepad file will be written. In the following examples, I'll assume you specified "notepad".

Create a subdirectory "notepad" in the "onlinenotepad" directory.

Upload script mynotepad.php into the "onlinenotepad" directory. (Make a note of the script's URL. The URL is the URL of your notepad page.)

Load the script into your browser and type something into the text box. Click the Update... button.

When the button is clicked, the page will reload. If the text box now contains what you previously typed, you are good to go. Otherwise, the subdirectory "notepad" will need 777 permissions. (Don't change "onlinenotepad" permissions to 777, only "notepad")

Using Simple Online Notepad

The URL of the PHP script is the URL of your notepad page.

To view or edit notes, send your browser or smart phone to the URL of the notepad page.

The Simple Online Notepad is useful for keeping notes that either need to be accessible whenever using a browser or need to be accessible on more than one browser/smart phone.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC