大网数据广告活动
网站运营与故障问答

How to check if a visitor is on my website?

· 52CE 我爱测

I want to build a website that only one person at a time can visit. How would I accomplish this task? I looked at Web counters built in php, but I don't think this is the right solution. Is there an http request for this? Thank y…

问题原文

原帖链接 · Matthias Pitscher · CC BY-SA 3.0

I want to build a website that only one person at a time can visit. How would I accomplish this task?

I looked at Web counters built in php, but I don't think this is the right solution. Is there an http request for this?

Thank you in advance.

已采纳解答

原帖链接 · L Martin · CC BY-SA 3.0

If you're looking to only serve content to one person at a time, this would be a server level mod. As an example for Nginx, you'd limit the number of active connections to 1:

server { limit_conn perserver 1; }

This serves a 503 error to anyone else that connects. It is possible to serve a custom page with the 503 error, alerting the user as to why they've received it.

If this doesn't suit your needs, you need to serve content to everyone but gate the 'real' content so that only one user at a time can view it. You'd create a page that everyone downloads with an embedded AJAX script. The script makes an API call to your server, asking if the 'page' is occupied. When it's not, the server assigns that page to the user session and returns the content. The script would then display this. Those not currently on the 'page' would be served a waiting page and continue to poll. This would also allow you to form an orderly queue on your server's side too.

Going into that territory, you're better off posting on Stackoverflow to ask how to make such a script.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2017-04-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。