Skip to content

Instantly share code, notes, and snippets.

@tobiasroeder
Created April 16, 2022 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasroeder/e4ef7d06d5dd5167f2de5b1bb0afeaaa to your computer and use it in GitHub Desktop.
Save tobiasroeder/e4ef7d06d5dd5167f2de5b1bb0afeaaa to your computer and use it in GitHub Desktop.
Locking/unlocking a website, e.g. for a landing page that is currently in a beta phase.
<h1>Coming Soon</h1>
<?php
// start the session to be able to read the unlock key
session_start();
// get the unlock key - as fallback the variable contains an empty string
$session_unlock_key = $_SESSION['unlock_key'] ?? '';
// check if the session unlock key is correct
// if not show the landing page
if ($session_unlock_key !== '__YOUR_SESSION_UNLOCK_KEY__') {
require __DIR__ . '/coming-soon.html';
exit;
}
// ...
<?php
// start the session to be able to remove the unlock key
session_start();
// clear all session variables
session_unset();
// remove all session data
session_destroy();
// redirect to the home directory, this will be in our case the index.php file
header('Location: /');
<?php
// start the session to be able to set the unlock key
session_start();
// set the unlock key
$_SESSION['unlock_key'] = '__YOUR_SESSION_UNLOCK_KEY__';
// redirect to the home directory, this will be in our case the index.php file
header('Location: /');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment