0

Im not sure what to do. im trying to make a session with my string inside of my function and parse the session outside of it , if that makes sense.... but im getting this error "SimpleXMLElement' is not allowed in session_write_close()" any suggestions on what i can do to solve it?

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);
Suzed
  • 487
  • 1
  • 6
  • 21
  • you're trying to store a SimpleXML object in the session... – Marc B Jul 23 '13 at 18:34
  • more so a array with the object inside, either way I gather that i am doing something incorrect here, so any advice on what to do? – Suzed Jul 23 '13 at 18:35
  • I'd suggest to take out the $_SESSION asignement out of the function (It's not the solution to your problem, but it'd make your function more generic) – Muc Jul 23 '13 at 18:51

1 Answers1

1

You need to serialize() the SimpleXMLElement (or any object) before it is stored in the session and then unserialize() it for use.

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

Alternatively you could just save the XML string used to create the object.

doublesharp
  • 26,888
  • 6
  • 52
  • 73
  • it says Serialization of 'SimpleXMLElement' is not allowed in serialize() as a error now, these are the changes i made. you will notice them at the bottom http://pastebin.com/yNgDc7pW – Suzed Jul 23 '13 at 18:48
  • Sorry, see this for more info: http://stackoverflow.com/questions/416548/forcing-a-simplexml-object-to-a-string-regardless-of-context – doublesharp Jul 23 '13 at 21:27