Forum Moderators: coopster

Message Too Old, No Replies

Limit ONE SESSION per user

Can I limit one session per one user in my php site?

         

mooeypoo

1:05 am on May 10, 2005 (gmt 0)

10+ Year Member



I am actually using a version of phpBB, but it's the same point since its all working on php.

Is there a way to limit sessions? As in, make sure that whether you're registered or not, you can only run ONE site-window, or two maximum?

The problem is that people open up over 4 windows (don't ask me why..) at a time, and my bandwidth runs out really fast.

I've tried to look up the different properties of Sessions in PHP but didnt find anything that specifically does that function... anyone? ideas?

Thanks!

~moo

ironik

1:16 am on May 10, 2005 (gmt 0)

10+ Year Member



The only way I know of to control this sort of functionality with PHP sessions is to setup your own custom session handler (PHP 4.0.1 or greater I think).

Check out the custom handler session_set_save_handler() in the PHP manual. It has a pretty good example of setting up custom functions to handle sessions. You can link these to a database and store extra information (such as an IP address or user_id) to try and make sure you have only 1 session running at once.

ironik

1:20 am on May 10, 2005 (gmt 0)

10+ Year Member



Oh, and this won't prevent them from opening more windows (which is entirely up to the user), it's only really useful for ensuring the same person isn't operating more that one account at a time. There may be some javascript that will allow you to control the number of windows a user can access your site through, but I haven't come across anything...

If people open up 4 windows at a time, how would that consume more bandwidth? The browser would normally cache all/most of the graphic files, and I'm sure they can only view and operate one window at a time. If something like that is causing you to run out of bandwidth I reckon it's time to change hosts.

Lord Majestic

1:21 am on May 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think JavaScript could do it -- since all pages belong to the same domain, you can name windows somewhat, and then use JavaScript to assign correct name to current one, and if it exceeds limit then say something to user.

But IMO trying to fight users preferences is a bad move, it just pisses people off. Make sure you have gzip compression enabled as it can cut down on HTML transfers 4-5 times.