簡體   English   中英

如何通過php中的系統命令替換exec()?

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

我的編碼到目前為止:

如何通過php中的系統命令替換exec()

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;
}

現在我想用系統命令替換exec命令?

我在這里使用三次exec() ,如上面的代碼所示,我想用php中的system ()命令替換

exec("hostname",$retval);
$output = exec($cmd,$array1,$error_code);
exec($cmd,$array1,$error_code);

要刪除單個文件,您應該使用取消鏈接並刪除應使用rmdir的目錄。 在這些頁面的注釋中,您會發現通過這些函數模擬rm -rf許多不同方法。

您應該盡可能避免使用systemexec 總是看看php.net和谷歌,看看你是否可以找到一種方法來做你正在嘗試使用內置函數或庫做的任何事情。 您無需在此使用這些設施。

hostname返回的內容應該使用$_SERVER['SERVER_NAME']代替。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM