Ok I want to get two timestamps using the time() function in php. One will be on registration the other will be on login. I want to subtract the login timestamp from the registration timestamp and get the number of seconds that have passed. How would I do this?
Easy Timestamp Question
| coreymanshack wrote: |
| Ok I want to get two timestamps using the time() function in php. One will be on registration the other will be on login. I want to subtract the login timestamp from the registration timestamp and get the number of seconds that have passed. How would I do this? |
if your using sessions you could do something like this:
| Code: |
|
<? session_start(); //this is on your registration processing page $_SESSION['reg_time']=time(); ?> |
and on your login page:
| Code: |
|
<? session_start(); $reg_time=$_SESSION['reg_time']; $seconds_passed=$reg_time-time(); ?> |
Something like that?
No I'm not using sessions... im using purely the time() function
here is what i have..
<?php
$userid = $_COOKIE[userid];
$conn = mysql_connect(localhost, ****, ****);
$db = mysql_select_db(game, $conn);
$sql_query = mysql_query("SELECT * FROM users WHERE ID='$userid'");
while ( $newArray = mysql_fetch_array($sql_query)){
$username = $newArray['username'];
$alliance = $newArray['alliance'];
$rank = $newArray['rank'];
$population = $newArray['population'];
$atkturns = $newArray['atkturns'];
$spyturns = $newArray['spyturns'];
$nxtturn = $newArray['nxtturn'];
$spank = $newArray['spank'];
}
$currenttime = time();
$currenttime -= $nxtturn;
$currenttime /= 60;
echo"$currenttime<br>";
if($currentime >= 15.0){
$currenttime /= $turnchange;
echo"$currenttime<br>";
$data_array = explode("." , $currenttime);
$whole = $data_array[0];
echo"$whole <br>";
$sql_query = mysql_query("UPDATE users SET atkturns='$whole' WHERE ID='$userid'");
$new = ".";
$new .= $data_array[1];
echo"$new <br>";
$new *= $turnchange;
$new *= 60;
echo"$new <br>";
$updatetime = time();
$updatetime -= $new;
echo"$updatetime";
$sql_query = mysql_query("UPDATE users SET nxtturn='$updatetime' WHERE ID='$userid'");
}
?>
For some reason it never goes into the if statement.
here is what i have..
<?php
$userid = $_COOKIE[userid];
$conn = mysql_connect(localhost, ****, ****);
$db = mysql_select_db(game, $conn);
$sql_query = mysql_query("SELECT * FROM users WHERE ID='$userid'");
while ( $newArray = mysql_fetch_array($sql_query)){
$username = $newArray['username'];
$alliance = $newArray['alliance'];
$rank = $newArray['rank'];
$population = $newArray['population'];
$atkturns = $newArray['atkturns'];
$spyturns = $newArray['spyturns'];
$nxtturn = $newArray['nxtturn'];
$spank = $newArray['spank'];
}
$currenttime = time();
$currenttime -= $nxtturn;
$currenttime /= 60;
echo"$currenttime<br>";
if($currentime >= 15.0){
$currenttime /= $turnchange;
echo"$currenttime<br>";
$data_array = explode("." , $currenttime);
$whole = $data_array[0];
echo"$whole <br>";
$sql_query = mysql_query("UPDATE users SET atkturns='$whole' WHERE ID='$userid'");
$new = ".";
$new .= $data_array[1];
echo"$new <br>";
$new *= $turnchange;
$new *= 60;
echo"$new <br>";
$updatetime = time();
$updatetime -= $new;
echo"$updatetime";
$sql_query = mysql_query("UPDATE users SET nxtturn='$updatetime' WHERE ID='$userid'");
}
?>
For some reason it never goes into the if statement.
echo"$currenttime<br>";
if($currentime >= 15.0){
There's your problem. The variable you want is $currenttime, and your if statement is checking $currentime - with one T.
Its usually something simple like that
if($currentime >= 15.0){
There's your problem. The variable you want is $currenttime, and your if statement is checking $currentime - with one T.
Its usually something simple like that
heh, taht wasn't all
but i got it all fixed now!
