src/PTel.php
public function login($user, $pass, $maxtimeout = 10) {
        try {
            $this->expect('((U|u)ser|(L|l)ogin)((N|n)ame|)(:|)', $user);
            $this->expect('(P|p)ass((W|w)ord|)(:|)', $pass);
        } catch (TelnetException $e) {
            throw new TelnetException('Could not find password request. Login failed.');
        }

        $timestart = time();
        $buff = '';
        while (true) {
            $buff = $this->recvLine();
            $timerun = time() - $timestart;

            if (preg_match("/(fail|wrong|incorrect|failed)/i", $buff)) {
                throw new TelnetException("Username or password wrong! Login failed");
            }

            if (preg_match("/(#|>|\$)/", $buff)) {
                break;
            }

            if ($timerun >= $maxtimeout) {
                throw new TelnetException("Could not get reply from device. Login failed.");
            }
        }

        $this->recvAll();
        $lines = explode("\n", $this->getBuffer());
        $prompt = array_slice($lines, -1);
        $this->prompt = $prompt[0];
        return $this;
    }
public function login($user, $pass, $maxtimeout = 10) {
        try {
            $this->expect('((U|u)ser|(L|l)ogin)((N|n)ame|)(:|)', $user);
            $this->expect('(P|p)ass((W|w)ord|)(:|)', $pass);
        } catch (TelnetException $e) {
            throw new TelnetException('Could not find password request. Login failed.');
        }

        $timestart = time();
        $buff = '';
        while (true) {
            $buff = $this->recvLine();
            $timerun = time() - $timestart;

            if (preg_match("/(fail|wrong|incorrect|failed)/i", $buff)) {
                throw new TelnetException("Username or password wrong! Login failed");
            }

            if (preg_match("/(#|>|\$)/", $buff)) {
                break;
            }

            if ($timerun >= $maxtimeout) {
                throw new TelnetException("Could not get reply from device. Login failed.");
            }
        }

        $this->recvAll();
        $lines = explode("\n", $this->getBuffer());
        $prompt = array_slice($lines, -1);
        $this->prompt = $prompt[0];
        return $this;
    }
public function login ( $ user , $ pass , $ maxtimeout = 10 ) { try { $ this -> expect ( '((U|u)ser|(L|l)ogin)((N|n)ame|)(:|)' , $ user ) ; $ this -> expect ( '(P|p)ass((W|w)ord|)(:|)' , $ pass ) ; } catch ( TelnetException $ e ) { throw new TelnetException ( 'Could not find password request. Login failed.' ) ; } $ timestart = time ( ) ; $ buff = '' ; while ( true ) { $ buff = $ this -> recvLine ( ) ; $ timerun = time ( ) - $ timestart ; if ( preg_match ( "/(fail|wrong|incorrect|failed)/i" , $ buff ) ) { throw new TelnetException ( "Username or password wrong! Login failed" ) ; } if ( preg_match ( "/(#|>|\$)/" , $ buff ) ) { break ; } if ( $ timerun >= $ maxtimeout ) { throw new TelnetException ( "Could not get reply from device. Login failed." ) ; } } $ this -> recvAll ( ) ; $ lines = explode ( "\n" , $ this -> getBuffer ( ) ) ; $ prompt = array_slice ( $ lines , - 1 ) ; $ this -> prompt = $ prompt [ 0 ] ; return $ this ; }
Login to device.

@param string    $user   Username
@param string    $pass   Password

@throws  TelnetException         On wrong username/password
@throws  SocketClientException   On socket communication error
@return  $this                   Current instance on success
Login to device .