简体   繁体   English

PHP-一次只能访问一台设备

[英]PHP - Give access to only one device at a time

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 ? 有没有办法在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. 我首先在服务器(lighttpd)中搜索了一个选项,然后搜索了某种htaccess,但我认为PHP是正确执行此操作的唯一方法。

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()
    ]));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM