Jump to content

IN NEED OF HELP


ngreenwood6

Recommended Posts

I have created a login for my website. It is working without a problem. When a user logs there username gets put into a session and they can view all the pages that they cannot when they arent logged in. However, I do not want users logging in twice with the same username. I have been trying to think of how I want to accomplish this but would like to know what your suggestions are. Please let me know how you would do it with maybe an example or tutorial.

 

Thanks in advance

Link to comment
Share on other sites

I do and I have the username stored in the session but how would I use the database for this. The problem that I see is that when a user just closes the page it doesnt log them out hence not updating the database. Any suggestions? This is why I am so stumped! I know that there are websites out there that do this though.

Link to comment
Share on other sites

Create a column... "logged" set it to either 0 or 1, and make a "lastAction" column that is updated every time a page loads, this will hold the time of the user's last action.

 

0 = logged out

1 = logged in

 

When a user logs in, check to make sure "logged" is not set to 1.

When a user logs out, change the 1 to a 0.

 

Now what if someone doesn't log out, and just closes the browser?

 

Make a cron job that runs every 1-5 minutes, it will check the "lastAction" column, and set all "logged" columns to 0 where the "lastAction" is greater than 5 minutes, or how ever long you want.

 

You will need to log a user out, if they have been idle for more than 5 minutes and come back, and are logged on somewhere else.

 

Hope this gets you started.

Link to comment
Share on other sites

Ok thanks for the help guys I get what you are saying and I think I know what I am going to do. However, I want to set it so that when the visit the next page it sets the current time in the database. How could I easily implement that into each page so that I do not have to add that code to every page that they will be logged into?

 

The main thing that I dont know how to do is:

 

make a "lastAction" column that is updated every time a page loads

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.