i am creating a webpage and i have a form inside of it. In one of my input box i want to set the current date automatically without the user inputting it. I am using the getDate() function of PHP but the problem is that people can change the date by changing their system date and time....
I want the real date and time.
$mydate=getdate(date("U"));
$date = "$mydate[weekday], $mydate[month] $mydate[mday], $mydate[year]";
<input value='$date'>
Help Guys
PHP date() function gets time from your system. So that a user can change his system time and data will have that time.
A solution would be, have a Timestamp field in your database table (I'm assuming that you are going to save the form data in a database) and that will take the time from the server, where the database is hosted.
The user can't change the server's time, so that a correct time will be updated.
You can use date() function to set current date and time automatically.
For example
<?php echo '<input type=text value="' . date("d F Y H:i:s") . '" readonly/>';?>
d : Day of the month, 2 digits with leading zeros (01-31)
F: A full textual representation of a month, such as January or March
Y: full numeric representation of a year, 4 digits (2017)
H: 24-hour format of an hour with leading zeros (00 through 23)
i: Minutes with leading zeros (00 to 59)
s:Seconds, with leading zeros (00 to 59)
The code you have provided sets the dat according to the server's date and time and in not affected by the users' system date and time: The one thing you can add so that the user cannot modify the date is the readonly flag:
$mydate=getdate(date("U"));
$date = "$mydate[weekday], $mydate[month] $mydate[mday], $mydate[year]";
The readonly attribute can be used like so:
<input value="<?php echo $date;?>" readonly="readonly">
OR
<input value="<?php echo $date; ?>" readonly>
If your code is inside php script then:
echo '<input value="'.$date.'" readonly>';