通过 phpseclib 写入带有“$_SERVER 文本”的 php 文件:SSH2
Write php file with "$_SERVER text" via phpseclib: SSH2
需要在 ssh 会话中创建文件 "index.php"。
已用:"phpseclib/phpseclib":“~2.0”,
$ssh = new SSH2("192.168.138.5", 22);
$ssh->login("user", "mypass");
$ssh->write("cd /home/user/\n");
$ssh->read('[prompt]');
$ssh->exec("cat > index.php <<EOF
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/header.php');
EOF\n");
$ssh->disconnect();
unset($ssh);
但结果是:
<?php
include(['DOCUMENT_ROOT'] . '/header.php');
如何在 ssh 会话中将“$_SERVER”文本写入文件?
在 $ 符号前添加反斜杠 \
\$_SERVER
解决方法是:
include(\$" . "_SERVER['DOCUMENT_ROOT'] . '/header.php');
需要在 ssh 会话中创建文件 "index.php"。
已用:"phpseclib/phpseclib":“~2.0”,
$ssh = new SSH2("192.168.138.5", 22);
$ssh->login("user", "mypass");
$ssh->write("cd /home/user/\n");
$ssh->read('[prompt]');
$ssh->exec("cat > index.php <<EOF
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/header.php');
EOF\n");
$ssh->disconnect();
unset($ssh);
但结果是:
<?php
include(['DOCUMENT_ROOT'] . '/header.php');
如何在 ssh 会话中将“$_SERVER”文本写入文件?
在 $ 符号前添加反斜杠 \ \$_SERVER
解决方法是:
include(\$" . "_SERVER['DOCUMENT_ROOT'] . '/header.php');