Software, your way.
burger menu icon
WillMaster

WillMaster > LibrarySecurity and Blocking

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!

One Page for Password and Content

When delivering content restricted to only one person, the page itself can require a password for access.

With this technique, no special password-protected area is required. The protection is built into the page itself, and only that one page has the restriction.

It is quick to implement.

No cookie is involved.

How it Works

When the page is first accessed, the user sees a form where they can type in their password.

If the correct password is provided, the page is reloaded with the content revealed. (Otherwise, the password form is presented again.)

The page can have whatever valid web page content you want it to have.

Here is the source code. Customization notes follow.

<?php
$password = "myPassword"; // Replace this password
//----------------------
// Version 1.1 of February 2, 2021, 16:45 EST
$passed = false;
$password = strtolower($password);
if( isset($_POST['access']) ) { $_POST['access'] = strtolower($_POST['access']); }
if( empty($_POST['access']) or $_POST['access'] != $password )
{
   echo <<<FORM
<div style="display:table; margin:.5in auto; font-size:1.2rem; border:3px solid #ccc; border-radius:1em; padding:1em;">
<form method="post" enctype="multipart/form-data" action="{$_SERVER['PHP_SELF']}">
Access code: <input type="text" name="access" style="width:3in; border:1px solid #666; border-radius:.25em; padding:.25em;">
<br><input type="submit" value="Submit Code">
</form>
</div>
FORM;
   exit;
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test 1</title>
</head>
<body>
SECRET CONTENT
</body>
</html>

Customization —

There are two places to customize.

  1. Replace myPassword at the second line from the top of the above source code with the password to be required for access to the secret content of the page.

  2. Replace SECRET CONTENT at the third line from the bottom of the above source code with the HTML content to be revealed when the correct password is provided.

Put the page on your website and test it. It should work exactly as designed: Provide the password to see the content.

(This article first appeared with an issue of the Possibilities newsletter.)

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