Hello and i hope that everyone is having a pleasant day,
I don’t know how to use Datetime to record a current time plus an expiration time for use with a CSRF token.
i don’t want to burden the forum with such a silly problem. I am new to PHP and i have no experience with certain things such as Datetime. I’ve never created a public website. I only ever made html or php pages for my own usage on my pc. Organizing photos, music (play mp3 via activex) etc.
I’ve tried $ndt = new DateTime();
and i cannot echo a the code because it has no value. Now i understand that this is an object and it is not a string that can be echoed. I see that people manually add a date time, as $ndt = new DateTime("2019-25-03 12:00:00");
but i cannot see how to add the current time dynamically. I wonder if i should even be using Datetime for this but i think that date interval would be easier to calculate an expiration time than to create an interval manually. Yet i don’t understand how to do this with Datetime();
I created CSRF tokens for use with forms but now i realize that these tokens are useless without an expiration date. So i’m trying to make a token as follows:
time() + time-to-live + random token.
maybe someone can offer some guidance as to using a datetime object to accomplish this task. I have tried a few methods but always get an error, especially when trying to echo a value, add to the date 15 minutes and even an error trying to echo an interval. Apparently, i don’t understand the Datetime object.