在php中使用exec设置系统时钟 [英] Using exec in php for setting system clock

查看:150
本文介绍了在php中使用exec设置系统时钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个PHP脚本,该脚本从浏览器获取一个时间戳值,并尝试设置系统时钟.我在Mac mini中使用Mamp框.如何通过php脚本设置mac mini系统时钟.

I am using a php script which takes a timestamp value from browser and tries to set the system clock. i m using mamp box in my mac mini. how do i set the mac mini system clock through php script.

我尝试使用shell_exec,exec,system来实现此目的,但是它不起作用.

I tried using shell_exec, exec, system for achieving this , but it doesn't work.

例如,我的php脚本看起来像这样,

Example, my php script looks something like this,

<?

$timestamp = $_GET['timestamp'];

exec('date '.$timestamp);

?>

当我在终端中尝试相同的日期设置命令时,我看到时钟在变化. (sudo date timestamp),但是我不知道如何通过执行特权命令的php脚本来实现它.请帮助.

When i try the same date set command in terminal i see the clock changing. ( sudo date timestamp ), but i dont know how to achieve it through php script executing a privileged command. Kindly help.

谢谢, 斯里尼.

推荐答案

更改系统时间通常仅限于根级帐户. PHP将在Web服务器的用户ID下运行,该用户ID不应为root.为此,您必须使用sudo来使Web服务器以提升的特权运行.

Changing the system time is usually restricted to root-level accounts. PHP will be running under the user id of the webserver, which SHOULD NOT BE root. You'll have to use sudo to let the webserver run with elevated privileges for this purpose.

但是,为什么需要这样设置时间戳?您基本上是将一些通过URL传递的随机数据传递给Shell命令.什么可以阻止某人提交

However, why do you need to set timestamps like this? You're basically passing some random data passed in on a url to a shell command. What's to stop someone submitting

  http://example.com?timestamp=; rm -rf /

并查看网络服务器上服务器上可以访问的每个文件吗?

and nuking every file on your server that the webserver has access to?

如果您尝试同步服务器之间的时间,请使用专门设计的 ntp 用于时钟同步.

If you're trying to sync times between servers, then use ntp, which is designed for clock synching.

这篇关于在php中使用exec设置系统时钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆