The Android application sends a POST request to the PHP server. How to pull out the unixtime value of the device from this request at the moment it sent it. It is clear that the time can be included in the request, but why if most likely it is already there.

  • one
    Which device is the client (time of sending the request) or server (time of receiving)? - PinkTux
  • Yes, the client, which on the device was the unix value of the time when it sent it. - Gennady
  • Theoretically, the HTTP request header may contain the string Date: ... with the time of its formation, but in practice clients rarely make it - avp
  • How can this date be pulled from the header into a variable? - Gennady
  • Probably $_REQUEST['date'] / In general, if you specifically ask someone, write @nick for notification - avp

2 answers 2

If you need a timestamp, then (as one of the options) you can add a variable to the POST request handler on the server, which will be assigned a time:

 $time = strtotime('now'); 
  • mktime it will be easier option like? - teran
  • if I understand correctly, people ask about time on the client - qpi
  • @teran, perhaps) php is generally quite a flexible language, there are different solutions. I just personally used strtotime in one of my projects, and everything works fine - humster_spb
  • @qpi, what is "time on the client"? You can get the opening time of the browser with the form (if the form contains the corresponding hidden field for sending time information). and you can get the time of arrival of data on the server. - humster_spb
  • @humster_spb means client time zone. > How to pull out from this request the unixtime of the device you see, people ask about the time of the device. Although unixtime is the same for everyone) but it seems that is what he means - qpi

No The server part is the server part, it does not know anything about the client except for the information that the client sends. And she really does not transmit anything.

All information on the request environment can be obtained by printing the global $_SERVER server variable $_SERVER

In order to get the device time, you need to pick it up with a javascript and pass it to a variable on the server.