我是全新的PHP
,並且有一個簡單的項目,我在做Java。 在我簡單的項目中,我有一些html
文件和一些Php
文件。 我在我的Php
網頁上通過SSH連接到設備,之後我將運行一些命令並返回SSH返回的數據。 任何方式,所以我設計了一個Html
文件登錄和使用,在我的php
,這裏是我的Php
代碼:不能調用靜態變量
<?php
class Connection {
public static $ip; // I even made static this variable to test if I can access Static variable from other
public $username;
public $password;
public static $ssh;
public function sshConnection() {
include ('./view/login.html'); // The html page contain variables
include('Net/SSH2.php'); // I use phpseclib to connect via SSH
if(isset($_POST['lgin'], $_POST['ip'], $_POST['username'], $_POST['password'])) { // Login button in html file
$this->ip = $_POST['ip']; // input type to get ip in html file
$this->username = $_POST['username']; // input type to get username in html file
$this->password = $_POST['password']; // input type to get password in html file
$this->ssh = new Net_SSH2($this->ip);
if (!$this->ssh->login($this->username, $this->password)) {
print('Login faild');
} else {
header("Location: http://localhost/wireless/configwireless.php"); // This redirect to next page that I should display some Commands
}
}
}
}
$connection=new Connection();
$connection->sshConnection();
?>
我需要在接下來的頁面$的ssh變量,這樣我可以通過這個連接上運行命令和開會。 我用Google搜索,找出我可以通過這個代碼訪問靜態變量:
classname::$variableName;
我還送了我的$ IP靜態變量來測試,如果我可以訪問或沒有,但沒有機會, 這是我configwireless.php
代碼:
<?php
echo Connection::$ip; // Does not display the input ip variable.
?>
但它不顯示$ip
變量。 我在哪裏做錯了?
你檢查'$ _POST'值? –
嘗試print_r($ _ POST)並檢查值是否正在顯示' – Exprator
您能解釋更多的人嗎? 我有點困惑。 :-) –