WEB DEVELOPMENT: A BRIEF HISTORY OF TIME()

January 1st, 2009

Part of a beauty of PHP to me is a series of unequivocally utilitarian variables which have been built in. Some of these competence appear really peculiar during first, though once we begin formulating pages we will run in to a little problems which you;ll find can be solved by a duty which seemed all invalid when we initial listened of it. One of these functions for me was time().

Echoing a time() duty will give we a volume of time upheld given a Unix Epoch in seconds. Say what? Epoch equates to a indicate in time selected as a begin of a duration or an epoch as well as to illustrate a Unix Epoch is January 1 1970 00:00:00 GMT. So echoing a time() duty will give us 1230978041%26#8243; during a time I;m essay this, definition which 1,230,978,041 seconds have upheld given then. So because is this utilitarian to us?

Mathematically it gives us a most simpler approach of gripping lane of time. Sure, 2008, January 15th competence appear all good as well as orderly to you, though to work out a days upheld from a 15th of Januaray to a 17th we;s have to frame a numbers of th , as well as in some-more formidable cases perform a garland of alternative fibre changes. Using time we can radically allot a series worth to any given second, creation it most simpler to use, generally as a counter.

The place we make make make make use of of of of it most is to record out users of a website automatically after an loitering period. When a user signs in we emanate all a event variables for him/her, as well as we additionally emanate a single which binds a time his event should expire. The beauty of this total complement is which we do not need to know a tangible time, we can only allot a worth to a event non-static similar to this:

$_SESSION['user']['time'] = time() +3600

This equates to which a user can stay logged in for 3,600 seconds (in alternative difference an hour) from this impulse in time. This is a really available approach of defining death time, given we can consider in conditions of how prolonged we wish it to be, as against to perplexing to work out a specific date as well as time.

When a user refreshes a page, or moves upon to a brand new one, a book will check a worth of a event variable. If a stream time is not as big than a event variable, a user can stay logged in as well as we additionally customarily lengthen a event by an additional 3,600 seconds. This gives it a loyal loitering aspect, given a user is authorised to stay logged in for some-more than an hour, as prolonged as he/she is regulating a system. You could however select not to lengthen a session, in this box a user would have to record in again after a single hour no make a difference what. In a little tall confidence systems this competence be a approach to go, or if we wish a user to outlay just a single hour upon a specific puzzle, there have been most uses for everything. Needless to contend which if a stream time is some-more than a event non-static a user is sealed out.

Another usual make make make make use of of of of for time() is to offer as a basement for generating a pointless ID, or impression set, in alternative words, it can offer as a seed. A utterly fit approach of formulating a really pointless fibre would be to make make make make use of of of of time(), order it by a pointless series generated in between 0 as well as 9,999, supplement a little pointless characters to it, as well as encode a total thing regulating a SHA1 algorithm for example. Code-wise this is not as formidable or as prolonged as it might sound, as well as it is flattering pointless as well as strong, nonetheless we am no confidence specialist.

if we have any cold uses for the time() duty let us know in a comments!

Author: Daniel Pataki
Web Development: A short story of time()

Uncategorized

  1. No comments yet.
  1. No trackbacks yet.