-4

I am facing the problem. How to print the local machine data and time on my php page using php. I did try a lot but no positive response. If there is possibility to print the local computer data and time then please give me suggestion.

Thanks in advance.

Jenz
  • 8,280
  • 7
  • 44
  • 77
Amy
  • 119
  • 2
  • 3
  • 12
  • show what you have done? you are on server side code – Rakesh Sharma May 17 '14 at 05:51
  • 3
    You can't. PHP runs on the server, so it never has visibility of the client machine - unless you send it the data via JS,a form, or some other method - in which case it is trivial as you already have it. – Fluffeh May 17 '14 at 05:51
  • 1
    Possible duplicate of http://stackoverflow.com/questions/2705067/how-can-i-get-the-users-local-time-instead-of-the-servers-time – 웃웃웃웃웃 May 17 '14 at 05:52
  • thank you Fluffeh .....for giving me this knowledge – Amy May 17 '14 at 05:53

1 Answers1

1

One thing I would do is, fire a call asynchronously from the client, using JavaScript. Say something like this:

<form method="post" action="settime.php" id="timeForm">
  <input type="hidden" id="localTime" name="localTime" />
</form>

And in the JavaScript:

document.getElementById("localTime").value =
        (new Date()).getDate() + "/" +
        (new Date()).getMonth() + "/" +
        (new Date()).getYear() + " " +
        (new Date()).getHours() + ":" +
        (new Date()).getMinutes() + ":" +
        (new Date()).getSeconds();
document.getElementById("timeForm").submit();

In the server side, you need to do something like this:

<?php
  $localTime = strtotime($_POST["localTime"]);
  // Do something with PHP
?>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252