0

How do I change the server time using PHP? From my research so far, I found you can execute any terminal line with the function exec(). What do I put into that function to say change the date and time to November 24, 2013 12:38?

The reason I must do this in PHP is I do not have access to the physical server, so everything must be done remotely. I have set up Cron Jobs before using exec(), so I should have permission to change the date as well.

7ochem
  • 2,183
  • 1
  • 34
  • 42
Kody
  • 752
  • 2
  • 11
  • 22

1 Answers1

2

Assuming the server is running on windows I believe you could do exec('time 12:38:00 PM') and exec('date 11/24/2013'). If it is a linux based server I think you can do something like this: exec('date -s "24 NOV 2013 12:38:00"'). Also you might want to look at this question. I realize it isn't the same but the person who answered brought up a good point about not running php as root in linux, assuming you are doing so.

I used this link for linux and this one for windows.

Community
  • 1
  • 1
Dan
  • 2,701
  • 1
  • 29
  • 34