I want to make a simple website on a local server that would be accessed by only one device at a time. I've found user management scripts but they are more more complex than what I am searching for. I don't need it to be password protected or have different kind of users and/or rights. Juste a page where only one person at a time can connect.
Is there a way to make it in PHP ?
I've first searched for an option in my server (lighttpd) then for some kind of htaccess but I think PHP is the only way to do it right.
Thank you for your consideration.
According to my comment above:
<?php
$minInterval = 5 * 60; // 5 minutes
$access = true;
if (file_exists('visitor')) {
$visitor = unserialize(file_get_contents('visitor'));
if ($visitor['addr'] != $_SERVER['REMOTE_ADDR']) {
if ($visitor['time'] + $minInterval >= time()) {
$access = false;
}
}
}
if (!$access) {
exit('Access denied.');
} else {
// Update last visitor data
file_put_contents('visitor', serialize([
'addr' => $_SERVER['REMOTE_ADDR'],
'time' => time()
]));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.