PHP
, test.php :
<?php
function mylog() {
$logFile = 'test.log';
$log = 'test';
exec(<<<BASH
cat >> $logFile <<EOF
$log
EOF
BASH
);
}
mylog();
php test.php (!):
rm -f test.log
php test.php
cat test.log
:
test
Bash:
<?php
function mylog() {
$logFile = 'test.log';
$log = 'test';
exec(<<<BASH
cat >> $logFile <<EOF
$log
EOF
BASH
);
}
mylog();
php test.php ,
:
rm -f test.log
php test.php
cat test.log
:
sh: line 2: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
test
EOF
-, Bash, Bash. Bash. , EOF .
, , OP Bash
exec , Bash. eval.
eval, :
eval "$(
cat <<'EOF'
cat >> test.log <<EOF2
log contents
EOF2
EOF
)"
, Bash "$( )". -doc cat <<'EOF' EOF, , ( ). log contents -doc, <<EOF2 EOF2.
Bash, , :
cmd="$(
cat <<'EOF'
cat >> test.log <<EOF2
log contents
EOF2
EOF
)"
rm test.log
eval "$cmd"; eval "$cmd"; eval "$cmd"
cat test.log
:
log contents
log contents
log contents
.