2

It`s need to create file "index.php" in ssh session.

Used: "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);

But result is:

<?php
include(['DOCUMENT_ROOT'] . '/header.php');

How to write "$_SERVER" text to file in ssh session?

Anton
  • 59
  • 6

2 Answers2

2

Add backslash \ before $ sign \$_SERVER

user492589
  • 571
  • 5
  • 11
1

The solution is:

include(\\$" . "_SERVER['DOCUMENT_ROOT'] . '/header.php');
Anton
  • 59
  • 6