Jump to content

for new php user's a example for timestamp settings.


redarrow

Recommended Posts

so tihs is how we use a timestamp using time() function.

 

when you echo the time function you get a unix timestamp.

<?php
echo time();
?>

 

If you add the date() function to the timestamp you get humun

readable date and time.

 

There are meny formats to set the date please read php.net.

<?php
echo date("d-m-y h:i:s",time());
?>

 

We know need to understand how to set a time via seconds

 

1*    <<< daye
60 * <<hour
60*  << seconds
24    << example is the hours within the day.

 

Putting it all together.

 

example

<?php

$this_is_one_minute=1*60*1;
//result 60 seconds

$this_is_half_hour=1*30*60*1;
//result  1800 seconds

$this_is_one_hour=1*60*60*1;
//result 3600 seconds
?>

 

Know we need to make a timestamp do somethink set

on seconds.


<?php

// get the time now in unix timestamp.

$time_now=time();

// set a valable to do somethink from the times learnt above.

//This example puts the time() function in then  +  adds 60 secounds to it.

// afther 60 secounds has gone past the $time_now varable the code would exicute.

$time_go=time()+(1*60*1);

if($time_now>$time_go){

echo "hello all you can see me becouse your 1 minute in front now";

}else{

echo " the time stamp not one minute in front yet";

}

?>

 

 

WARNING $time_now will never execuite becouse this is an example in

a real life situation you would use the time for $time_now form your database.

 

 

know you can protect your form posting with a flood controll with the timestamp well done!

Please go away and learn basic math and English before attempting a "tutorial" again redarrow. Your poor spelling and grammar make it very difficult to follow what you are trying to say and why the hell are you multiplying numbers by 1, several times?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.