matty Posted March 14, 2007 Share Posted March 14, 2007 Hey, I need a bit of help coding a users online pieace of code. What I want is to display how long ago it was since the user last clicked a link on my page? How would i go about doing this? Cronjobs, MySQL and everything is open to me. Many thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/ Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 MySQL and a Link Management type script. Basically all your links have to go through a file IE: link.php?linkid=3 would be http://www.google.com And in the link.php file is where you would do the data processing ie: <?php //link.php // process db calls etc here. // Redirect user using link from database. header("Location: " . $linkURLFromDB); die(); ?> --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207432 Share on other sites More sharing options...
matty Posted March 14, 2007 Author Share Posted March 14, 2007 I see, Couldnt I just, record a timestamp to a database with the username/ID then set up a cron job to delete all enteries that are more than say 10minutes old? I only need this for one page, and doing it the way you suggest would mean big modifications to my script. I have 50+ pages... from what I understand I will have to change all the links in there, correct? Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207439 Share on other sites More sharing options...
The Little Guy Posted March 14, 2007 Share Posted March 14, 2007 http://snippets.tzfiles.com/snippet.php?id=22 Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207441 Share on other sites More sharing options...
matty Posted March 14, 2007 Author Share Posted March 14, 2007 That seems to be more like what I want, I guess using a cron is going to be pretty pointless, when all I need is it to check everytime someone checks the page, its not like a meaninful task. Il try out something. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207444 Share on other sites More sharing options...
matty Posted March 14, 2007 Author Share Posted March 14, 2007 Okay, I have made use of that script you showed me. I now have it so it displays when the user is online, or if there offline. What I need is like a last action script. Something to tell me HOW LONG AGO their last action was, for example 1 minute ago. How can I do this? Many Thanks, Matt EDIT - I have it so it display when they were last active in date format, but i want how long ago from the current time they were last active... If you get me... Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207480 Share on other sites More sharing options...
The Little Guy Posted March 14, 2007 Share Posted March 14, 2007 What kind of action? The last URL they were at? Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207484 Share on other sites More sharing options...
matty Posted March 14, 2007 Author Share Posted March 14, 2007 Its for a game, so i have sessions etc... Its basically when they were last active. When they last did something in the game, so yeah clicking something. I could probally get away with using timestamps here couldnt I? Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207488 Share on other sites More sharing options...
The Little Guy Posted March 14, 2007 Share Posted March 14, 2007 Time stamp would only display time. You would need to store information into a database for each user. and overwrite their old data evertime they do something. I then would create a function that is in every file and this would get information that you want, such as the current URL they are at, and store it into the database. Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207496 Share on other sites More sharing options...
matty Posted March 15, 2007 Author Share Posted March 15, 2007 I have a sperate file which is included in all my files.. but I still think you missing the point. I need to know how long AGO they were active. Say they last click a link 30 seconds AGO, i need to display the 30 seconds how would I get this? Would I store a timestamp from when the user acessed the page (did something) and then take it away from the current timestamp when another user looks at that users profile page so that you get this... Last action timestamp - current timestamp = timestamp which will have the time in between now and the last action they made... I can do that, but who do i display it? I would need seconds... when it gets to 60 seconds i would need minutes, and then hours and then days... how would i code this? Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-207641 Share on other sites More sharing options...
matty Posted March 17, 2007 Author Share Posted March 17, 2007 No one can help? Quote Link to comment https://forums.phpfreaks.com/topic/42746-user-online-code/#findComment-209214 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.