--- ~/gateway_clickatell_http.inc	2006-09-03 17:53:51.000000000 +0200
+++ ./smsgateway/gateway_clickatell_http.inc	2007-07-18 15:35:51.000000000 +0200
@@ -208,9 +208,15 @@
     var $session;
 
     /**
+    * Auth result
+    * @var mixed
+    */
+    var $auth_result;
+
+    /**
     * Class constructor
     * Create SMS object and authenticate SMS gateway
-   * @param new_api_id API ID value
+    * @param new_api_id API ID value
     * @param new_user user/account name
     * @param new_password password to use
     * @param new_use_ssl whether to use SSL
@@ -221,7 +227,7 @@
         $this->api_id = $new_api_id;
         $this->user = $new_user;
         $this->password = $new_password;
-	$this->use_ssl = $new_use_ssl;
+	      $this->use_ssl = $new_use_ssl;
         if ($this->use_ssl) {
             $this->base   = "http://api.clickatell.com/http";
             $this->base_s = "https://api.clickatell.com/http";
@@ -240,7 +246,7 @@
     * @access public
     */
     function build_connection_string() {
-    	return sprintf ("%s/auth?api_id=%s&user=%s&password=%s", $this->base_s, $this->api_id, $this->user, $this->password);
+    	return sprintf("%s/auth?api_id=%s&user=%s&password=%s", $this->base_s, $this->api_id, $this->user, $this->password);
     }
 
 
@@ -251,7 +257,14 @@
     * @access private
     */
     function _auth() {
-        $this->session = $this->_parse_auth ($this->_execgw( $this->build_connection_string()));
+        $this->auth_result = $this->_parse_auth($this->_execgw($this->build_connection_string()));
+        if (strpos($this->auth_result, "Failed") === false) {
+          $this->session = $this->auth_result;
+          return "OK";
+        }
+
+        $this->session = '';
+        return $this->auth_result;
     }
 
     /**
@@ -273,6 +286,10 @@
     * @access public
     */
     function send($to=null, $from=null, $text=null) {
+      /* Check session */
+      if (!$this->session) {
+        return $this->auth_result;
+      }
 
     	/* Check SMS credits balance */
     	if ($this->getbalance() < $this->balace_limit) {

