Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Working with Time

    Hello all another question for you hehe,

    Now,, This is what I am looking to do...

    1. A user logs in, a time is entered into his/her database.

    2. When they come back and try to login again, the database is checked for there last login, if it has been 24 hours since the last login they get a point, if not they are just logged in and can move about the site...

    Now I did this in perl by useing the mktime() module...

    I have no clue How I can accomplish this in php...

    In perl I turned the time to unix and hten subtracted the two times...

    Is there a way to do that in php?

    Any help is most apprecaited!
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can basically do it the same way

    php has a whole host of date and time functions, but rather annoyingly there's no simple comparison function.

    http://uk.php.net/manual/en/ref.datetime.php is a list of all the functions.

    The one you'll be interested in is time(); just call that to return a unix timestamp, personally i like to just throw this into an integer field in mysql, but most people here would prolly advise against this.

    If you do choose to do it my way then you can store the timestamp in the DB and just use the following for 24 hours ago:

    $back24 = time() - 86400;

    then just select from the DB where date is less than $back24.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can do this much easier and efficient through SQL.

    You didn't specify your db-format or anythinh, but suppose you hav mySQL and you run an update on your usertable and lastlogin is the tile of your previous login, then your condition would look like :

    $sql=("UPDATE usertable SET points = points+1 WHERE (lastlogin + INTERVAL 24 HOUR) > Now() and user=" . $_POST[user] );

    Every db has its own goodies for doing stuff like this.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I will check out the time() module thanks readMe...

    I am using noraml .dbs as in -- NAMEOFFILE.db

    To put mySQL on the server is 50 dollars and my client can't afford it yet so We are going with .db...

    Anyways, Im pretty sure that timestamp in time() will serve the purpose very nicly...
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •