issue <? phpinfo(); ?> and get your version. The "private" keyword began in PHP 5.
Regards, ken http://kennethtucker.com --- In [email protected], "Michael Sullivan" <[EMAIL PROTECTED]> wrote: > > I'm trying to work with the ssh2 class found at > > http://us2.php.net/manual/en/function.ssh2-auth-password.php#56285 > > to provide user authentication to my server using my users system > usernames and passwords, but I'm having trouble. I copied the code > into its own file and then used require_once to include it. The ssh2 > class is giving me a lot of errors, and as I don't know PHP very well, > I just wanted to ask: Is this valid PHP? Is this a problem with my > server or with the code itself? I'm using mod_php-4.4.0-r9 with > apache-2.0.54-r31 . Here's the code: > > <?php > > class SSH2 > { > private $con; > private $host; > private $port; > private $login; > > public function __construct($host=NULL, $port=22) > { > $this->host = $host; > $this->port = $port; > > $this->con = ssh2_connect($this->host, $this->port); > // connection attempt successful ? > if($this->con === false) > { > $this->con = NULL; > throw new SSH2Exception("Could not connect to host > '".$this->host."' on port ".$this->port); > } > } > > public function login($login=NULL, $password=NULL) > { > if(empty($login)) { > throw new IllegalArgumentException("Login failed, no > username supplied"); > } > $this->login = $login; > > // try to log in > if(!ssh2_auth_password($this->con, $this->login, $password)) > { > $this->con = NULL; > throw new SSH2Exception("Password authentication failed for > user '".$this->login."'"); > } > } > > // returns an array like: array('stdout goes here', 'stderr') > public function exec($cmd) > { > if(empty($this->con)) { > throw new SSH2Exception("Exec failed, no connection > available"); > } > // execute the command > $stdio = ssh2_exec($this->con, $cmd); > // get the error stream, otherwise this would be lost > $stderr = ssh2_fetch_stream ($stdio, SSH2_STREAM_STDERR); > // set to blocking mode or we won't get any data > stream_set_blocking($stdio, true); > > $data_std = ''; > $data_err = ''; > // let's fetch the result of our command > while($data = fread($stdio, 131072)) { > //while($data = fgets($stdio)) { > $data_std .= $data; > } > while($data = fread($stderr, 80000)) { > $data_err .= $data; > } > // close the streams > fclose($stdio); > fclose($stderr); > > return array($data_std, $data_err); > } > } > > class SSH2Exception extends Exception {} > class IllegalArgumentException extends Exception {} > > ?> > > > The first line it trips on is line 5: private $con; > > It gives me > > Parse error: parse error, unexpected T_STRING, expecting > T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in > /home/michael/webspace/html/testing/ssh2.php on line 5 > > If I replace the "private" with "var" line 5 doesn't generate an > error. The above code looks like pseudo-java to me. Can anyone help > me figure this out? > ------------------------ Yahoo! Groups Sponsor --------------------~--> Most low income households are not online. Help bridge the digital divide today! http://us.click.yahoo.com/I258zB/QnQLAA/TtwFAA/HKFolB/TM --------------------------------------------------------------------~-> Community email addresses: Post message: [email protected] Subscribe: [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] List owner: [EMAIL PROTECTED] Shortcut URL to this page: http://groups.yahoo.com/group/php-list Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-list/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
