dongshi1934 2011-09-27 05:19
浏览 123

如何通过php中的系统命令替换exec()?

My Coding is so far:

How to replace exec() through system command in php?

if($str!="success")
{
    $cmd = "rm -rf /portal/data/config/certificate/tmp/";
    $error_text="Command : ".$cmd;
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    $output = exec($cmd,$array1,$error_code);
    $error_text="Error code : ".$error_code;
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    seterror('0:|:  :|: Could not apply certificate.');
    $error_text="Could not apply certificate";
    AddLog("sslconfig.php",$error_text,ERR_INFO);
    header("Location: ssl.php");
    exit;
}

if($certName==$cert_auth)
{
    //copy the applied certificate to fireballbundle.crt
    //$output = copysslfb("/portal/data/config/certificate/".$newfile.".crt");
    $error_text="Selfsigned Certicate";
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH); 
    $output="success";
} 
else 
{
    $error_text="Not Selfsigned Certicate";
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    $output="success";
}

if($output!="success")
{
    $cmd = "rm -rf /portal/data/config/certificate/tmp/";
    $error_text="Command : ".$cmd;
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    $output = exec($cmd,$array1,$error_code);
    $error_text="Error code : ".$error_code;
    AddLog("sslconfig.php",$error_text,ERR_DEBUG_HIGH);
    $error_text="Could not add certificate to fireballbundle.crt : ".$output;
    AddLog("sslconfig.php",$error_text,ERR_ERROR);
    seterror('0:|: :|: Error in applying certificate.');
    header("Location: ssl.php");
    exit;
}

Now I want to replace exec command with system command ?

I am using three times exec() here as shown as above code now i want to replace with system () command in php

exec("hostname",$retval);
$output = exec($cmd,$array1,$error_code);
exec($cmd,$array1,$error_code);
  • 写回答

1条回答 默认 最新

  • dongliqian6245 2011-09-27 05:42
    关注

    To remove a single file, you should use unlink and to remove a directory you should use rmdir. In the comments on those pages, you will find many different ways to emulate rm -rf through these functions.

    You should avoid using system or exec as much as is possible. Always look on php.net and google to see if you can find a way to do whatever you're trying to do with a built-in function or library. You have no need to use these facilities here.

    What hostname returns you should probably use $_SERVER['SERVER_NAME'] for instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog