Passing Multiple PHP Variables to Shell_Exec()

Passing multiple PHP variables to shell_exec()?

There is need to send the arguments with quota so you should use it like:

$page = shell_exec("/tmp/my_script.php '".$my_url."' '".$my_refer."'");

Exec or Shell_exec: variables don't pass from php to the script

Doubles quotes should be at the beginning of the string.

'some string "$var" somestring' // won't interpolate
"some string '$var' somestring" // will interpolate

or you can concatenate them to the string

exec('../ems-scripts/mass-email-send.sh ' . $subject . ' ' . $body, $output)

You can read this discussion Should I use curly brackets or concatenate variables within strings? your problem is more about variable concatenation and interpolation, than really about exec() and shell_exec()

Passing GET variables to shell_exec in PHP

GET-parameters are accessed via $_GET-variable. Notice the underscore before the "GET".

http://php.net/manual/en/reserved.variables.get.php

How can I pass parameters from php to a script in linux?

! Use the function escapeshellarg to prevent from shell injection attacks:

$asd = escapeshellarg($name);
for($i=0; $i<count($checkbox); $i++){
$raid = $checkbox[$i];
$asd = $asd ." ". escapeshellarg($raid);
}

$last_line = exec("sh /var/www/proyecto/borrarraid1.sh ". $asd, $output, $retval);

$output_delimiter = '<br/>'
if ($retval !== 0) {
echo "Error while executing command", $output_delimiter;
echo implode($output, $output_delimiter);
} else {
echo "The command was executed successfully", $output_delimiter;
echo implode($output, $output_delimiter);
}

PS: exec() manual page: http://php.net/manual/en/function.exec.php



Related Topics



Leave a reply



Submit