Skip to main content
Known Participant
December 16, 2010
Question

PHP and MySQL login system

  • December 16, 2010
  • 3 replies
  • 2599 views

Hi,

I am working on a php and mysql login system.

I am creating a login system which tracks the user activity. The time and date gets saved into the database when they last logged on. My client requires to know how many times a user has logged in between two dates. The only way I can think of doing this is inserting into the database every time they have logged in (time and date) and then carry out a query of when the user has logged on between date1 and date2.

At the moment the database updates the last time they logged in. So would it be best to insert every time they log in as appose to updating? Is this the best way to do it?

Thanks

This topic has been closed for replies.

3 replies

February 12, 2011

Hi,

Getting the PHP and Mysql Login system with Dreamweaver is pretty cool job.

I have developed numerous Php based applications.


I started using Dreamweaver since 2003.

I am amazed by the ease at which i can work on Coding.

Thanks to Adobe.

SeeToronto

Sr Web Developer Toronto

http://www.giantcanada.com Classifieds

Participating Frequently
December 16, 2010

By just having a count of the number of times a user logs in, you lose the ability to query for the number of times between two arbitrary dates.  If you know the dates that the customer is concerned about a priori, then you can just create a counter and update by one.  When the end date occurs, do the query and reset the counters.

If, however, you have no prior knowledge of the date range your client wants to query on, unfortunately you are going to at least have a counter per day per user - meaning that if a user logs in on day n, then you need to start a counter for day n and update it every time that user logs in on that day.  When day n+? occurs and the user log in, then you have to start a new counter for that user.

The question I would ask the client is for how long do you need to retain that information?  If you provide the information for the number of times the user logs in between date1 and date2, can you then delete that data?  If the client never asks for the information for a particular user, how long do you have to keep that data?  While the client every ask for a query between date1 and date2 and then later ask for the information with a date range and includes or intersects with the previous date range request?

There are a lot of requirements missing here and without knowing them, you could code yourself into a corner and have a maintenance nightmare on the database.

Walter

B & B Photography

ultrasuite
Inspiring
December 16, 2010

Walter is absolutely right.  My method would only give you a count of total logins and not a count of logins between specific dates which is what the OP asked.  Sorry, I missed that.

dips045Author
Known Participant
December 17, 2010

Thanks for the feedback guys...

I forgot to mention that I also have a login counter for each user but this was not enough for my client.

I spoke to my client briefly today and they said that they would like to export the login database every month. Is this something I can automate?

Thanks again for your help! :-D

ultrasuite
Inspiring
December 16, 2010

What you mentioned would probably work but it is not the most efficient method especially if there are going to be frequent visits by the users. You could create a numeric field in your login table - something like visit_count.  Everytime someone logs in retrieve the value of that column, add one to it and update the record with the new value.  From efficiency point of view, I would prefer this.

J.S.

http://www.ultrasuite.com/