ssh2_auth_password()
함수 (및 ssh2_connect()
도 마찬가지입니다.)에서 오류를 처리하는 데 어려움을 겪고 있습니다. 원격 서버에 연결하고 로그인 할 때 나는 성공적으로 관리하지만, 잘못된 자격 증명을 제공 할 때는 이러한 경우를 처리 할 수 있기를 원합니다. ,잘못된 ssh2_auth_password() '오류가 발생했습니다.
try {
// Préparation à la copie en SSH du fichier template
$scp = new My_Controller_Plugin_Scp();
$scp->auth(); // Authentification
} catch(Exception $e) {
echo $e->getMessage();
$this->getHelper('Redirector')->setGotoRoute(array(), 'ficheVoir');
exit();
}
실제 출력은 : 나는 ZF 1.12를 사용하고 있는데 나는 그래서 플러그인 조금 컨트롤러를 만들었습니다
<?php
class My_Controller_Plugin_Scp extends Zend_Controller_Plugin_Abstract
{
private $host;
private $login;
private $password;
private $destDir = '.';
private $connexion;
public function __construct()
{
$co = ssh2_connect($this->getHost(), 22);
if(false === $co)
throw new Exception('Can\'t connect to remote server');
$this->setConnexion($co);
}
/**
* @return bool
* @throws Exception
*/
public function auth()
{
$auth = ssh2_auth_password($this->getConnexion(), $this->getLogin(), $this->getPassword());
if($auth === false)
throw new Exception('Authentication failed!');
return $auth;
}
을 그리고 난 이렇게 내 컨트롤러에서이 플러그인을 사용하고 있습니다 내가 사용자 정의 오류 메시지를 표시 할 수 있기를 원하는 반면 자격 증명을 엉망으로 만들 때 PHP 경고가 표시됩니다.
내가 Exception
과 관련하여 뭔가 잘못하고있는 것이 있습니까?
무엇이 오류 메시지입니까? –
잘못된 자격 증명을 제공했기 때문에 '경고 : ssh2_auth_password() : 암호를 사용한 로그인에 실패했습니다.'라는 메시지가 예상대로 나타납니다. – D4V1D
이것은 어리 석으나 반환 값을'$ auth' 변수에 할당하지 않고'if'에서 함수를 호출하려고합니다. 또한 @를 사용하여 오류를 억제하십시오. –