Capture visitor’s local time

Asked

Viewed 525 times

0

Hello, for security reasons I need to pick the time the visitor of the page entered, but the system apparently is taking time from the server.

IP: [XXX.XXX.XXX.XXX] Date: [03-07-2017 - 14:05:49] (Local time 11:05)

I’m using the following code

$ip = $_SERVER['REMOTE_ADDR'];  
$data = date("d-m-Y - H:i:s"); 

What I could use to catch the time of Brazil(Official time of Brasilia) ?

  • 1

    First you should understand that the methods shown are executed on the server, that is, it will return information from the server. For security issues you should really capture the server date yes, after all the destination is the same. I believe that the correct thing is to synchronize the server clock, until it is expected that the client-side time may not be the same with the other clients.

  • What is this crazy security that depends on an arbitrary data easily falsifiable by the user?

1 answer

3


Normally the log time is the server itself, as @Diego Vieira said several users may have different times, but answering your question

What I could use to catch the time of Brazil(Official time of Brasilia) ?

If you only wanted a specific date in another Timezone, that of São Paulo for example

$dt = new DateTime('now',new DateTimeZone('America/Sao_Paulo'));
echo $dt->format('d-m-Y - H:i:s');

Or you can use the date_default_timezone_set function to set the default Timezone of the application

date_default_timezone_set('America/Sao_Paulo');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.