Jump to content

Allow only 1 user on site


googlexx

Recommended Posts

What scenario are you wishing to achieve this? Is the redirect permanent?

 

What I'd recommend is creating a table, and when the page is viewed it enters 'viewed = 1' for example and if another user comes on it'll have that value and you can appropriately redirect them, A cron job can set 'viewed' back to false if you wish it to reset.

Link to comment
Share on other sites

Well, essentially there is no method of doing this unless you:

 

A) Make them click an exit link, which will expire the session (if the exit this will not happen)

B) Create a cron job and set the table to refresh at a set time if no one is  'logged' to the page.

Link to comment
Share on other sites

start a session when they visit the page and when session is there make it to 1 and when the session got killed make it as 0

 

That could work as well, but it'd be a timed session, meaning the person cannot view the page after a certain amount of time (albeit an easier solution).

Link to comment
Share on other sites

alright this is what i have so far

a couple problems im having:

 

it's not logging the ip's and i am not able to be on the page 2 times on the same ip.

i'm also trying to make it so when someone is online and they are the only person on it lets them. But when someone else tries to connect I would like it to start like a 60 second timer. When that timer ends it redirects the person that waited the 60 seconds back to the site and removes the person already on the site. I know this is possible but how hard it is? I don't know php very well but I'll try my best with any help!

 

<?
//online

$server = "localhost";

$db_user = ""; 

$db_pass = ""; 

$database = ""; 

$timeoutseconds = 20; // length of gaps in the count



//get the time

$timestamp = time(); 

$timeout = $timestamp-$timeoutseconds; 



//connect to database

mysql_connect($server, $db_user, $db_pass); 


//delete values when they leave

$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout"); 

if(!($delete)) { 

    print ""; 

} 



//grab the results

$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); 

if(!($result)) { 

    print ""; 

} 



//number of rows = the number of people online

$user = mysql_num_rows($result); 

//check if someone is online
if($user >= 1) {
ob_start();
header("Location: http://www.google.com");
ob_flush();
}
else {
//no1 is online - add them

$insert = mysql_db_query($database, "INSERT INTO useronline VALUES

('$timestamp','$REMOTE_ADDR','$PHP_SELF')"); 

if(!($insert)) { 

     print ""; 

} 
} 
mysql_close();
?>

 

Thanks!

Link to comment
Share on other sites

There is no solution for what you want to do. There are work arounds but the fact is that there is no way to know exactly when a user exits a page. I can click a link that says goodbye but I could also walk away and leave the browser window open all night long. Maybe I just close the window, the heck with your exit link or button.

 

It might help if you explained exactly what you are doing and why.

 

HTH

Teamatomic

Link to comment
Share on other sites

Well you could have the user click a link to "Check out" the file and then it is in their name/ip address until they click a link to "Check in" the file, like in Joomla file edit. And as a fail safe, if they don't check out within a certain period of time or they don't refresh the page within a certain period of time (you can set the page to refresh with javascript if they are still viewing the page and therefore if they aren't viewing the page then the page won't refresh and the file will be checked back in)... or something like that

Link to comment
Share on other sites

let me try to explain it better:

 

1. A user joins a page. (User A)

2. He stays on the page for 10 minutes.

3. Another user joins that same page. (User B)

4. It tells (UserB) someone else is already on the page and starts a 60 second timer for them.

5. It goes back to the page (User A) is on and shows him that someone else is trying to go on the page. It then shows him the 60 seconds timer.

6. When the 60 second timer finishes it redirects (User A) off the page and redirects (User B) onto the page.

 

I hope that makes sense. So far i have everything done except the part with the timer and redirecting.

Link to comment
Share on other sites

You need Ajax to create the dynamic bit both for user A and B. However creating a table just specifically for this functionality is overkill but without a table it's hard to implement. The obvious choice would be if you store your sessions in a db table add the message to the session record that is viewing page X user A who is viewing the page then just retrieves in regular intervals it's session data. Then if you find the predefined variable(s) for page messages in the json response display it to the user viewing the page. Start an internal clock using setTimeout() (JS) that will redirect the user to the next page when the 60 seconds clock stops.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.