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
https://forums.phpfreaks.com/topic/123963-in-need-of-help/
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
https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639969
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
https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-639985
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
https://forums.phpfreaks.com/topic/123963-in-need-of-help/#findComment-640066
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.