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

WBOY
Release: 2016-06-23 13:34:28
Original
1035 people have browsed it

这是一个我试验成功的例子,测试环境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技术论坛

    source:php.cn
    Statement of this Website
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template