Shadowing Posted December 19, 2011 Share Posted December 19, 2011 After doing some reading im trying to make sure I understand how all this time stuff works with using sql I have a Session created for users that uses $_SESSION['login_time'] = time(); when I echo that it comes up as 1324245123. so the reason it looks like that is because that is what UNIX looks like? So thats why this code doesnt work if ($get1['date'] > strtotime('-1 minutes')) { because the date im getting from $get1 is a sql time stamp and the strtotime is UNIX and they dont match do I understand this right? Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 It looks like that because those are seconds. UNIX time is the amount of seconds since January 1, 1970. You can't directly compare MySQL's time/date functions to UNIX timestamps, but you can if you convert them to UNIX first. Try: if(strtotime($get1['date']) > strtotime('-1 minutes')) { By the way, strtotime() calculates its time based off the current timestamp. So if you want to compare it to the timestamp your session holds, you need to give it the timestamp as a second parameter. Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 19, 2011 Author Share Posted December 19, 2011 now im really lost into why im having this issue am I reading this right if state equals 1 and 1 minute goes by mysql_query happends other wise kick off my lock out works fine but now trying to add a time into it and right now its letting the mysql_query happen before 1 minute goes by this is what my time stamp from date looks like 2011-12-18 23:22:44 <?php if ($safe1['state'] == 1){ if(strtotime($get1['date']) < strtotime('-1 minutes')) { mysql_query("UPDATE users SET state='' WHERE id = '".mysql_real_escape_string($_SESSION['user_id'])."'"); mysql_query("DELETE FROM `banned` WHERE `id`= '".mysql_real_escape_string($_SESSION['user_id'])."'"); }else{ header("Location: signup.php?reason=$get&name=$get5"); session_destroy(); exit(); } }?> Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 You know, if the date is stored in a MySQL time/date format, then you can use DATE_ADD in a WHERE clause to update the table if 1 minute has passed. Makes this a lot easier. Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 19, 2011 Author Share Posted December 19, 2011 this is crazy so im doing some tests this doesnt work with lastactive equals the format of 'NOW' if(strtotime($get7['lastactive']) < strtotime('-1 minutes')) but this does work if ($_SESSION['login_time'] < strtotime('-1 minutes')) with login_time equaling the format of "time" Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 19, 2011 Author Share Posted December 19, 2011 oh wait im dumb haha i forgot to remove the unix conversion on if(strtotime($get7['lastactive']) < strtotime('-1 minutes')) { will test that now Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 19, 2011 Author Share Posted December 19, 2011 apparently it gives a error on the "<" trying to compare NOW with strtotime I dont know what i was talking about earlier. NOW isnt in unix format so it would have to be converted anyways i just read in the manual that NOW is the same format as time stamp is that correct? so i should compare to that instead of strtotime. im confused on how adding a minute to my time stamp is going to work with my script. id still have to be comparing it to something or am I missing something Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 Read: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 19, 2011 Author Share Posted December 19, 2011 You mean something like this? if one minute doesnt go by it ignores anything after it? didnt think things worked like this. really trying hard to figure out what you mean. mysql_query("SELECT date FROM `banned` WHERE `DATE_SUB(CURDATE(),INTERVAL 1 MINUTE`= > date_col "); Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 19, 2011 Author Share Posted December 19, 2011 the problem with that though is it has no idea which row its reading the time from. thats why i dont understand how i can use Where cause then i cant choose which row Quote Link to comment Share on other sites More sharing options...
Shadowing Posted December 19, 2011 Author Share Posted December 19, 2011 Been reading like crazy today. I didnt know php only uses UNIX time Since im going to be using a ton of time comparisions i think i should just store UNIX time in a INT column and just use php time on everything until i have to display the time. still have no clue how the add date works in my favor 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.