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");
开发者_如何学JAVAthis 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()
orescapeshellcmd()
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
精彩评论