Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda