Jump to content

php n xml..


gingar

Recommended Posts

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 = pfsockopen('ssl://www.example.com', 443, $errno, $errstr, 60);
    $fp = fsockopen($host, 80, $errno, $errstr, 60);
    $retval='';
    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'?>
	<root>
		<header>
			<protocol>1</protocol>
			<oem>supplier</oem>
			<agentID>11111</agentID>
			<password>password</password>	
			<sessionID>5bcsx0ut3e0pck45fikpgd55</sessionID>
		</header>
		<body>
			<opCode>OP_SET_INFO</opCode>
			<deferPayment>0</deferPayment>
			<reserveDetails>
				<step>SAVE_RES</step>
			</reserveDetails>
			<pfileNumOnlyInResponse></pfileNumOnlyInResponse>
		</body>
		</root>
";

$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));
}

xml_parser_free($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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.