當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ntlm_sasl_client_class::initialize方法代碼示例

本文整理匯總了PHP中ntlm_sasl_client_class::initialize方法的典型用法代碼示例。如果您正苦於以下問題:PHP ntlm_sasl_client_class::initialize方法的具體用法?PHP ntlm_sasl_client_class::initialize怎麽用?PHP ntlm_sasl_client_class::initialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ntlm_sasl_client_class的用法示例。


在下文中一共展示了ntlm_sasl_client_class::initialize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: authenticate

 /**
  * Perform SMTP authentication.
  * Must be run after hello().
  * @see hello()
  * @param string $username The user name
  * @param string $password The password
  * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
  * @param string $realm The auth realm for NTLM
  * @param string $workstation The auth workstation for NTLM
  * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth)
  * @return bool True if successfully authenticated.* @access public
  */
 public function authenticate($username, $password, $authtype = null, $realm = '', $workstation = '', $OAuth = null)
 {
     if (!$this->server_caps) {
         $this->setError('Authentication is not allowed before HELO/EHLO');
         return false;
     }
     if (array_key_exists('EHLO', $this->server_caps)) {
         // SMTP extensions are available. Let's try to find a proper authentication method
         if (!array_key_exists('AUTH', $this->server_caps)) {
             $this->setError('Authentication is not allowed at this stage');
             // 'at this stage' means that auth may be allowed after the stage changes
             // e.g. after STARTTLS
             return false;
         }
         self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
         self::edebug('Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), self::DEBUG_LOWLEVEL);
         if (empty($authtype)) {
             foreach (array('CRAM-MD5', 'LOGIN', 'PLAIN', 'NTLM', 'XOAUTH2') as $method) {
                 if (in_array($method, $this->server_caps['AUTH'])) {
                     $authtype = $method;
                     break;
                 }
             }
             if (empty($authtype)) {
                 $this->setError('No supported authentication methods found');
                 return false;
             }
             self::edebug('Auth method selected: ' . $authtype, self::DEBUG_LOWLEVEL);
         }
         if (!in_array($authtype, $this->server_caps['AUTH'])) {
             $this->setError("The requested authentication method \"{$authtype}\" is not supported by the server");
             return false;
         }
     } elseif (empty($authtype)) {
         $authtype = 'LOGIN';
     }
     switch ($authtype) {
         case 'PLAIN':
             // Start authentication
             if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
                 return false;
             }
             // Send encoded username and password
             if (!$this->sendCommand('User & Password', base64_encode("" . $username . "" . $password), 235)) {
                 return false;
             }
             break;
         case 'LOGIN':
             // Start authentication
             if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
                 return false;
             }
             if (!$this->sendCommand("Username", base64_encode($username), 334)) {
                 return false;
             }
             if (!$this->sendCommand("Password", base64_encode($password), 235)) {
                 return false;
             }
             break;
         case 'XOAUTH2':
             //If the OAuth Instance is not set. Can be a case when PHPMailer is used
             //instead of PHPMailerOAuth
             if (is_null($OAuth)) {
                 return false;
             }
             $oauth = $OAuth->getOauth64();
             // Start authentication
             if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
                 return false;
             }
             break;
         case 'NTLM':
             /*
              * ntlm_sasl_client.php
              * Bundled with Permission
              *
              * How to telnet in windows:
              * http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
              * PROTOCOL Docs http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
              */
             require_once 'extras/ntlm_sasl_client.php';
             $temp = new stdClass();
             $ntlm_client = new ntlm_sasl_client_class();
             //Check that functions are available
             if (!$ntlm_client->initialize($temp)) {
                 $this->setError($temp->error);
                 $this->edebug('You need to enable some modules in your php.ini file: ' . $this->error['error'], self::DEBUG_CLIENT);
                 return false;
//.........這裏部分代碼省略.........
開發者ID:pingyen,項目名稱:PHPMailer,代碼行數:101,代碼來源:class.smtp.php


注:本文中的ntlm_sasl_client_class::initialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。