Jump to content

Question about UNix time


Shadowing

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();
}
}?>

Link to comment
Share on other sites

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"

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ");

Link to comment
Share on other sites

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 :(

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.