Grow your CSS skills. Land your dream job.

PHP Get Current Time HELP

  • # July 15, 2013 at 3:53 am

    Hi, I’m currently working on a Download request link system. It involves a client that will input his email then the system will generate a **link** that will be sent to the email provided. This link contains the email which is converted to md5 and the time that it has been generated (for purpose of link expiration). I’m just confused with the time stamp since the system will be used by clients all over the world, how am I supposed to get there own time stamp and convert it to my server time so that I could make a valid expiration query.

    I hope you get me. I’m really having trouble here. ;(

    __
    # July 15, 2013 at 4:25 am

    >since the system will be used by clients all over the world, how am I supposed to get there own time stamp and convert it to my server time so that I could make a valid expiration query.

    Use _your_ timestamp. And _don’t_ convert it – unix timestamps use UTC time. It’s the same everywhere.

    $now = time();
    $expiry = 60 * 60 * 24; // 60sec x 60min x 24hrs
    if( $user_timestamp < ($now - $expiry) ){
    print “your timestamp has expired.”;
    }

    You can convert timezones when you actually need to display a readable date (or, better yet, _don’t_ – let javascript do it (since it knows the user’s TZ better than you do:

    script>
    var timestamp = < ?php time(); ?>;
    var date = new Date( timestamp*1000 );
    alert( date.toString() );

    )).

    # July 15, 2013 at 4:30 am

    This is completely out of my area but what about grabbing the user’s local timestamp with Javascript and then using that data with PHP?

    and @traq answers. I should have refreshed.

    __
    # July 15, 2013 at 12:10 pm

    >what about grabbing the user’s local timestamp with Javascript and then using that data with PHP?

    problem there is that you’re giving control of the expiration date to the user.

    # July 15, 2013 at 11:14 pm

    @traq , hey sorry for not responding quickly. It took me overnight to understand everything. I googled a lot of different definitions of Time, GMT, Epoch and everything concerning PHP Time stamp till I finally understand not just the meaning but how they work and then I finally understood what were you trying to explain with the code you had given. And now I’m laughing at myself :D HAHA I was that slow… Anyway. Thank you guys @traq, @chrisburton for giving attention to my question. Cheers!

    __
    # July 16, 2013 at 2:22 am

    no problem… solved? Glad I could help.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".