Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
Getting the real time and date in PHP

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

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

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.

about 4 years ago · Santiago Trujillo Denunciar

0

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)

about 4 years ago · Santiago Trujillo Denunciar

0

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>';
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda