SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: php n xml

  1. #1
    SitePoint Member
    Join Date
    Oct 2005
    0 Post(s)
    0 Thread(s)

    php n xml

    i have this site that i just did, that uses xml to pull info from my supplier.

    i'm using this.

    function send_request_test($data, $path, $host) {    
        $header = "POST ".$path." HTTP/1.0\r\n";
        $header .= "Host: ".$host."\r\n";
        $header .= "Content-Type: text/xml\r\n";
        $header .= "Content-Length: " . strlen($data) . "\r\n\r\n";
        // open socket
        $fp = fsockopen($host, 80, $errno, $errstr, 60);
        if (!$fp) {
            return "Error: " . $errstr;
        else {
            fputs($fp, $header.$data);
            while (!feof($fp)) {
                $retval .= fread($fp, 1024);
            fclose ($fp);
        return $retval;
    $test_xml = "
    <?xml version ='1.0' encoding='UTF-8'?>
    $test_content = send_request_test($test_xml, $test_path, $test_host);
    $pos = strpos($test_content, '<body>');
    if ($pos === false) {
        //echo "The string '$findme' was not found in the string '$mystring'";
    } else {
    	$test_data = substr($test_content, $pos);
    	$xml_parser = xml_parser_create();
    	xml_set_element_handler($xml_parser, "startTag_reservation", "endTag_reservation");
    	xml_set_character_data_handler($xml_parser, "contents_test_reservation");
    	if(!(xml_parse($xml_parser, $test_data))){
    		die("Error on line " . xml_get_current_line_number($xml_parser));
    the above code appears to send and receive the data i requested. However, the sessionID that is supposed to be returned with the data changes with each response. This should not be the case, as i tried sending the exact same xml via a standalone xml program (SendXML) the sessionID remained consistent.

    Is there anything that i might have missed or included that somehow resets the xml request? or anything? i was stuck on this for 1 whole week before it suddenly hit me that the sessionid wasn't consistent.

    Please help!

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    0 Post(s)
    0 Thread(s)
    Is there anything that i might have missed or included that somehow resets the xml request?
    My guess would be the fsockopen().
    It probably ignores the session cookie, thus the target server keeps sending a new one.
    If this is important to you, try to use curl functions to fetch the datas.
    You can specify that it must keep the cookies from query to query, by using a "query jar" to store them
    CURLOPT_COOKIEFILE The name of the file containing the cookie data. The cookie file can be in Netscape format, or just plain HTTP-style headers dumped into a file.
    CURLOPT_COOKIEJAR The name of a file to save all internal cookies to when the connection closes.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts