开发者

How to use php variable insisde system command

How do I use a PHP5 variable inside a system() call

$dir = '/etc/somedir';

eg system("ls $dir")

I think I'm missing something

I am actually passing a variable from a post

e.g.

$username = $_POST[username];

to a system call

system("processData --user $username --pass $password");

开发者_如何学JAVA

this isn't working, so i trivialised down to a simple example


You are doing it fine except that you are missing semi-colon (;)

system("ls $dir");

You can also do like:

system("ls" . $dir);

Note:

When allowing user-supplied data to be passed to this function, use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands.


it looks like you are not.. could you extend your example? are there any errors returned? what does the system() function return?

you should keep in mind that system() returns only the last line of the run command.

also, instead of 'ls' you can use a built-in php function like dir() or DirectoryIterator


0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜