Access-Restricted Page
Let's say you have a content page for only one or a few people. Perhaps a download link. Or a secret message. Something.
You want to keep search engines out of it. And also AI slurpers.
Also a log file so you can see when it was accessed.
And, yes, it should be simple.
As long as we're at it, can it please work without cookies?
If you're smiling, and even if you're not, today's article provides the code for that.
It's one file. The top part lets you provide one or more access codes. Folks will need one of these to gain access to your content. Further below in the file is where you provide the content.
The code is below. Notes follow.
<?php /* Access-Restricted Page Version 1.0 October 10, 2026 Will Bontrager Software LLC https://www.willmaster.com/ */ // Specify one access code per line between lines containing word CODELIST $AccessCodes = <<<CODELIST c.o.d.e Every Tuesday humanize CODELIST; $logfilename="loginlog.txt"; $passed=false; if(isset($_POST['CODE'])) { $ta=array(); foreach(preg_split('/[\r\n]/',trim($AccessCodes)) as $code) { if(!preg_match('/\S/',$code)){continue;} $ta[]=strtolower(trim($code)); } $putcode = strtolower(trim($_POST['CODE'])); foreach( $ta as $code ) { if($putcode==$code) { file_put_contents(__DIR__."/$logfilename",date('r')."\t{$_POST['CODE']}\t{$_SERVER['REMOTE_ADDR']}\t{$_SERVER['HTTP_USER_AGENT']}r\n",FILE_APPEND); $passed = true; break; } } } if(!$passed) { echo <<<FORM <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Provide Access Code</title></head><body> <form action="{$_SERVER['PHP_SELF']}" method="post"> <div style="max-width:3in; margin:.25in auto;"> <h3>Access Code:</h3> <input type="text" style="font-size:2rem; width:100%;" name="CODE"> <p><input type="submit" value="Submit Code"></p> </div></form></body></html> FORM; exit; } ?> <!-- The section above is the PHP to manage the page access. The section below is the web page that the logged-in person will see. --> <!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>YOUR PAGE TITLE</title> <style type="text/css"> html { font-family:sans-serif; font-size:100%; } a { text-decoration:none; } </style> </head> <body> [PAGE CONTENT GOES HERE] </body> </html>
Notes:
As mentioned, there are two sections. About a dozen lines from the top, you'll see this.
c.o.d.e
Every Tuesday
humanize
Those are codes (one line per code) that can be used to access the page. Replace those with your own list of codes. Each code on a line by itself. Codes may have spaces within them, but space at the ends will be ignored.
A few lines from the bottom of the file, you'll see this.
[PAGE CONTENT GOES HERE]
That's a placeholder for your content. Replace it with the content you want to present to those who gain access to your page.
Upload the page and test it.
When it works as it should, provide the URL and an access code to those who should have access.
(This content first appeared in Possibilities newsletter.)
Will Bontrager

