Home  >  Article  >  Backend Development  >  如何让PHP以root权限执行系统命令

如何让PHP以root权限执行系统命令

WBOY
WBOYOriginal
2016-06-23 13:34:281036browse

这是一个我试验成功的例子,测试环境SLES11SP1。

  1. php
  • //更改系统时间
  • function rootCmd($cmd_body)
  • {
  •   $cmd_head = "su --login root --command";
  •   //$cmd_body = "date -s 07/13/2005";
  •   $rootpasswd = "nari";
  •   $cmd_full = sprintf("%s \"%s\"", $cmd_head, $cmd_body);
  •   $fp = popen($cmd_full, "w");
  •   fputs($fp, $rootpasswd);
  •   pclose($fp);
  •   return 1;
  • }
  • ?>??
  •  

    原文来自 Techfox IT技术论坛

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn