0

我不知道该怎么办。我试图在我的函数内部与我的字符串进行会话并在它之外解析会话,如果这有意义的话....能做些什么来解决呢?

function api_info($form, &$form_state){

        $server_url = 'website api url'

        curl_setopt($ch,    CURLOPT_URL,               $server_url              );
        curl_setopt($ch,    CURLOPT_POST,              0                        );
        curl_setopt($ch,    CURLOPT_POSTFIELDS,                                 );    
        curl_setopt($ch,    CURLOPT_HTTPHEADER,        array("Expect:")         );
        curl_setopt($ch,    CURLOPT_FAILONERROR,       1                        );
        curl_setopt($ch,    CURLOPT_FOLLOWLOCATION,                             );
        curl_setopt($ch,    CURLOPT_HEADER,            false                    );
        curl_setopt($ch,    CURLOPT_RETURNTRANSFER,    1                        );
        curl_setopt($ch,    CURLOPT_SSL_VERIFYPEER,    false                    );
        curl_setopt($ch,    CURLOPT_SSL_VERIFYHOST,    false                    );

        curl_setopt($ch,    CURLOPT_TIMEOUT,           120                      );
        curl_setopt($ch,    CURLINFO_HEADER_OUT,       true                     );
        curl_setopt($ch,    CURLOPT_HTTP_VERSION,      CURL_HTTP_VERSION_1_1    );

        $xml_response_lead_point = curl_exec($ch);
        $xml_request_lead_point = new SimpleXMLElement($xml_response_lead_point);


        $result = reset($xml_request_lead_point->sm);

        $xml_request = $xml_request_lead_point;

        $xml_results = array(
                'lead_response' => $result,
                'results'       => $xml_request,
        );

        //dvm($xml_results['results']);
        //dvm($xml_request_lead_point);
        //dvm($a);

        $_SESSION['lead_results'] = $xml_results['results'];

        return $xml_results;
}

$lead_results = $_SESSION['lead_results'];
var_dump($lead_results);
4

1 回答 1

1

您需要serialize()将 SimpleXMLElement(或任何对象)存储在会话中,然后unserialize()将其用于使用。

$xml_obj = new SimpleXMLElement( $xml_string );
$_SESSION['xml_value'] = serialize( $xml_obj );
$xml_obj2 = unserialize( $_SESSION['xml_value'] ); 

或者,您可以只保存用于创建对象的 XML 字符串。

于 2013-07-23T18:35:58.087 回答