N-Bomb(Nerd) Posted November 7, 2011 Share Posted November 7, 2011 Hello, I'm trying to create a system where I can monitor where people are at on my website (so I'll be able to see which specific page their on). However, I've ran into a snag, because I have no idea where to start. There isn't an account system used so it has to be based off ip address and I only wanted to display active people within the last 15 minutes. So, I'm assuming this has to be session/cookie based, but I've never had to work with that before. I'm a complete loss and I've tried looking up tutorials online, but I'm not getting any real good results. Could anyone point me in the right direction? Thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 7, 2011 Share Posted November 7, 2011 1. Create a table to store the activity in. You'll need columns for at least 'ip' and 'page'. NOTE: You can have many users with the same IP if they are behind a router using NAT. So, you can't be sure that each IP is a unique user or not. Anyway, on each page load you will want to insert and/or update records in the table with the ip of the user and the page they requested. So, you could also use a session or cookie value to try and identify separate users on the same IP. Each has some benefits and drawbacks. Cookies can be deleted by the user or the user might not even accept cookies. But, on the other hand, cookies can be set to persist over time so they will be available over different sessions allowing you to track users consistently. Sessions cannot be modified by the user, but they also expire when the browser is closed. So a user who access your site, closes the browser and re-accesses the site will show two different users. If think you will ONLY ever want the current page of the user, then you would use an "INSERT ON DUPLICATE KEY UPDATE" query. That way if there is already an entry for that IP the previous entry will be overwritten by the new one. However, if you think that the historical data will ever be needed, then always do an insert. You can get the users most recent activity by applying the correct ORDERing and GROUPing logic in the query. Quote Link to comment Share on other sites More sharing options...
N-Bomb(Nerd) Posted November 8, 2011 Author Share Posted November 8, 2011 1. Create a table to store the activity in. You'll need columns for at least 'ip' and 'page'. NOTE: You can have many users with the same IP if they are behind a router using NAT. So, you can't be sure that each IP is a unique user or not. Anyway, on each page load you will want to insert and/or update records in the table with the ip of the user and the page they requested. So, you could also use a session or cookie value to try and identify separate users on the same IP. Each has some benefits and drawbacks. Cookies can be deleted by the user or the user might not even accept cookies. But, on the other hand, cookies can be set to persist over time so they will be available over different sessions allowing you to track users consistently. Sessions cannot be modified by the user, but they also expire when the browser is closed. So a user who access your site, closes the browser and re-accesses the site will show two different users. If think you will ONLY ever want the current page of the user, then you would use an "INSERT ON DUPLICATE KEY UPDATE" query. That way if there is already an entry for that IP the previous entry will be overwritten by the new one. However, if you think that the historical data will ever be needed, then always do an insert. You can get the users most recent activity by applying the correct ORDERing and GROUPing logic in the query. Thank you for the reply. I'll be diving into this later today so if anyone has any other input that would be appreciated. Quote Link to comment Share on other sites More sharing options...
N-Bomb(Nerd) Posted November 8, 2011 Author Share Posted November 8, 2011 I'm still at work and will be heading home soon to work on this. I've tried looking for some more tutorials or something that's descriptive or in-depth at all and I'm not coming up with any good results. Does anyone have a good tutorial or want to go in detail? :'( Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 8, 2011 Share Posted November 8, 2011 My site has 3 examples of this (with code). The first result was posted by me and works, but you will need to modify it (requires a database), the other 2 I haven't tried, and don't know if they will work for you because they don't use a database. http://phpsnips.com/search.php?search_by=1&q=online&submit=Search Quote Link to comment Share on other sites More sharing options...
N-Bomb(Nerd) Posted November 8, 2011 Author Share Posted November 8, 2011 My site has 3 examples of this (with code). The first result was posted by me and works, but you will need to modify it (requires a database), the other 2 I haven't tried, and don't know if they will work for you because they don't use a database. http://phpsnips.com/search.php?search_by=1&q=online&submit=Search Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.