출처 : http://www.chonnom.com/bbs/board.php?bo_table=WEB&wr_id=16

shell_exec 함수를 이용하면 PHP상에서 쉘명령어에 대한 결과값을 웹상에 출력할수 있다.
안전모드상에서는 실행되지 않으니 php.ini 파일을 확인
 safe_mode = Off
mojily_test.php
 
<?php
$data1 = shell_exec("ls -l /home/");
echo "<pre> $data1 </pre>";
$data = shell_exec("df -Th");
echo "<pre> $data </pre>"
?>
 
 
웹에서의 출력결과

그렇다면 웹에서 명령어를 직접적어 전송하는 과정을 보면...
test.html
<html>
<form action="mojily_test.php" method="get">
INPUT CMD : <input type="text" name="value1">
<input type="submit" value="전송">
</form>
</html>
 

 
mojily_test.php
<?php
$data = shell_exec("$value1");
echo "<pre> $data </pre>";
 
 
아래와 같은 창에 명령어를 적어주면 동일한 결과가 출력된다.


shell_exec

(PHP 4 , PHP 5)
shell_exec --  Execute command via shell and return the complete output as a string

Description

string shell_exec ( string cmd)

This function is identical to the backtick operator.

참고: 이 함수는 안전 모드에서 사용할 수 없습니다.
AND