2

This is my code

class WcfClient {
public $wcfClient = null;
public $user = null;

public function __construct(){
    if(isset($_SESSION['APIClient']) && $_SESSION['APIClient'] != null){
        $this->wcfClient = $_SESSION['APIClient'];
    }
}

public function __destruct(){
}

// Authanticate
private function Authenticate(){
    global $_sogh_soapUrl, $_isDebug, $_sogh_header;
    $wcargs = array();
    $consumerAuthTicket = null;
    if($this->wcfClient == null){

        $args = array(
            'clubname'=>'Wellness Institute at Seven Oaks',
            'consumerName'=>'api',
            'consumerPassword'=>'api'
        );

        try{

            $wcargs = array(
                'soap_version'=>SOAP_1_2
            );

            if($_isDebug){
                $wcargs = array(
                    'soap_version'=>SOAP_1_2,
                    'proxy_host'=>"192.168.0.1",
                    'proxy_port'=>8080
                );
            }

            // Connect to the API with soapclient
            $soapAPIClient = new SoapClient($_sogh_soapUrl, $wcargs);

            $response = $soapAPIClient->AuthenticateClubConsumer($args);

            if(isset($response->AuthenticateClubConsumerResult)){

                if(isset($response->AuthenticateClubConsumerResult->IsException) && $response->AuthenticateClubConsumerResult->IsException == true){
                    // some error occur
                    $this->wcfClient = null;
                    $_SESSION['APIClient'] = $this->wcfClient;
                } else{
                    // set consumer ticket
                    $consumerAuthTicket = $response->AuthenticateClubConsumerResult->Value->AuthTicket;

                    // $loginData = $responseCode->ReturnValueOfConsumerLoginData;

                    $headers = array();
                    $headers[] = new SoapHeader($_sogh_header, "ConsumerAuthTicket", $consumerAuthTicket);
                    $soapAPIClient->__setSoapHeaders($headers);

                    // add to session
                    $this->wcfClient = $soapAPIClient;
                    $_SESSION['APIClient'] = $this->wcfClient;
                }
            }
        } catch(SoapFault $fault){
            $this->error('Fault: ' . $fault->faultcode . ' - ' . $fault->faultstring);
        } catch(Exception $e){
            $this->error('Error: ' . $e->getMessage());
        }
    }

    return $this->wcfClient;
}

I store the soap client object in $_SESSION['APIClient'], but second times when run some data has been changed in session, I am use this class in drupal 7, I want to save the time using session, because authenticating takes long time. Please help Thank in advance

1
  • 1
    Not sure if it would help, but you could try calling drupal_session_start(); prior to adding your values to the session. Here are a list of other drupal core session functions that might help you debug: api.drupal.org/api/drupal/includes%21session.inc/7
    – scott
    Commented Oct 17, 2015 at 10:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.