Mobile app version of vmapp.org
Login or Join
Miguel251

: How to check if a visitor is on my website? 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,

@Miguel251

Posted in: #Http #Webserver

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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Miguel251

2 Comments

Sorted by latest first Latest Oldest Best

 

@Chiappetta492

You can use something like NodeJS. This is serverside javascript, with a template for the visitor. This template connects to the serverside JS (it's easier than it sounds).

The advantage of using NodeJS (or another serverside javascript language) is that the moment the logged in user leaves, another can join. You can broadcast a "we have room for one" signal, and maybe via a cue the next one joins. And you can give all the other users a nice message instead of a (customized) error page and possibly a queue.

It works similar to AJAX, but reversed. With AJAX you ask the server "Can I go in yet?" periodically, whilst the socket by NodeJS has a small connection open, and the server triggers the "OK, I'm available now". This allows for a more userfriendly alternative.

10% popularity Vote Up Vote Down


 

@Kimberly868

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme