FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Easy Timestamp Question





coreymanshack
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?
Slammer
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?
coreymanshack
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.
Karrde
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 Wink
coreymanshack
heh, taht wasn't all Smile but i got it all fixed now!
Related topics
*OFFICIAL* Which Browser do you use?
I am looking for some advice
The Bible Is Useful, Even For Athiests
Easy PS question; I really should know this...
Teachers, and understanding
California Surplus Projected! Citizen vote YES on taxes
Question about DNS!
Good old question: What is the the best CMS
linux question...
Changements to the Points/frih$ system (Discuss)
Interview Tips: Handling Difficult Question
How easy is it set up a business in yr country?
Silly Question i'm sure...
Webalizer question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.