justinede Posted October 23, 2008 Share Posted October 23, 2008 I need a simple php script that goes in my MYSQL database every 2 hours and changes data in a row. Like if i have a row called "logged_in" and every time a user logs in it puts a 1 in that row. If the account is attempted to be logged in from another place and the 1 is still there, it denies access. So essentially it prevents two people being on at the same time. But the user closes the browser and forgets to log out. The 1 is still in the database. So i need a script that every 2 hours goes through and changes all the 1s to 0s in the row "logged_in" any help please? Quote Link to comment Share on other sites More sharing options...
.josh Posted October 23, 2008 Share Posted October 23, 2008 Well it sounds like you have a solid battle plan. Break it down and do it step by step. Basic database handling, logging time last logged in, run a cron job on the script to execute every 2 hours. So hop to it sir. If you get stuck on some coding let us know, we'll try to help you out. If you are wanting someone to write it for you, make a post in the freelance forum making an offer. Quote Link to comment Share on other sites More sharing options...
justinede Posted October 23, 2008 Author Share Posted October 23, 2008 lol yeah solid battle plan but i need some help. could you possibly point me in the right way? give me something to look up that could help me accomplish this? Quote Link to comment Share on other sites More sharing options...
.josh Posted October 24, 2008 Share Posted October 24, 2008 Sure, start off with some basic database handling. Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 ok thanks but i dont think it says how to run a query like every 2 hours. Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 24, 2008 Share Posted October 24, 2008 From what you say, I thought about it this way. Make a SQL statement altering the "logged_in" column when the user logs in. Set the default as 1. "If the account is attempted to be logged in from another place and the 1 is still there" - From that i would log their IP or something like that (I don't know how to log someone's IP dont ask, lol) then if their not from that IP, then deny their access. "every 2 hours goes through and changes all the 1s to 0s" - This is just me saying it. Set a timer at certin times to alter that field at specific times to go to a 0. Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 yeah thats kinda what i need. but i dont know how to make a timer. haaha and the default for logged in is 0. when they log in, it sets it to 1. Quote Link to comment Share on other sites More sharing options...
.josh Posted October 24, 2008 Share Posted October 24, 2008 well you wanted pointing in a direction to start. I think you should start with writing the script so that you have something to actually run every 2 hours. Once you have your script, google how to run a cron job. Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 oh.. i know how to do the database part just wanted to know how to make it run every two hours. i dont think i can do a cron job. its yahoo hosting with their cruddy admin panel. and im using phpMyAdmin for my database.. Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 bump* Quote Link to comment Share on other sites More sharing options...
jwilliam Posted October 24, 2008 Share Posted October 24, 2008 If you want to run a script every two hours on a *nix platform (I'm not familiar with IIS) you need to use the crontab. If your hosting provider doesn't allow you access to your crontab then you may want to consider switching. However, I'm not sure your approach to session handling is on the money. If you run a script every two hours to change the 'logged_in' field to 0... and I logged in five minutes before the cron script ran then I'll be logged out for no apparent reason. I would think about a different approach to session handling. Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 ok how about i log wat time they login in a row and 2 hours from that it puts it back to a 0. would i still have to use crontab? cause i am not familiar with that and im almost positive yahoo doesnt give me that kind of access. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 24, 2008 Share Posted October 24, 2008 Why don't you just put a timestamp in the database for when the user logs in? And when someone logs in see if its over 2 hours? If it is, reset your login bit, if not, dont. I dont really see the need for a cron job for this. Quote Link to comment Share on other sites More sharing options...
n3ightjay Posted October 24, 2008 Share Posted October 24, 2008 http://www.webcron.org/ .. Some language i don't know ... but runs cron jobs for you ... maybe further searching could find an english version ... but just shy of hitting a page yourself every 2 hours or some demented javascript page that you have to keep open all the time this is the only option i can see for you dilema of not being able to set up a cron job Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 thats what i just said. ^^ Quote Link to comment Share on other sites More sharing options...
n3ightjay Posted October 24, 2008 Share Posted October 24, 2008 a side note .. i agree the logic of your problem needs to be re-assessed Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 24, 2008 Share Posted October 24, 2008 Yeah, I was typing when you were.... Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 ok so can anyone help me make a script that will look at the time logged in and change the 1 to a 0 after 2 hours? please and thank you! Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 24, 2008 Share Posted October 24, 2008 Im sure people will if you have tried and couldn't get it to work and you've posted your code. They're most likely not just going to do it for you. Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 haha ok well i know how to add a time stap to a row but i dont know how to like analyze it and make it work.. haha Quote Link to comment Share on other sites More sharing options...
justinede Posted October 24, 2008 Author Share Posted October 24, 2008 actually i have a time stamp go in when they log out. so to make one when they log in, would i put the following code in this line? time stamp code: $time = time(); timeout = NOW() that is in my logout.php now to add it to my login does it go in here? $sql="SELECT logged_in FROM $tbl_name WHERE username='$myusername' and password='$mypassword' AND activated='1'"; $result=mysql_query($sql); Quote Link to comment Share on other sites More sharing options...
jwilliam Posted October 25, 2008 Share Posted October 25, 2008 Yeah, you're on the right track now, I'd say. You're authentication algorithm could be something like this: On all password-protected pages: - check to see if they're logged in - if they are, check the last time they logged in - if that was more than two hours ago, log them out and send them to the login page - if they aren't, send them to the login page 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.