
hardik.mehta.b
Novice
Feb 2, 2011, 9:44 AM
Post #1 of 1
(60106 views)
|
Could not find xmlResponse tags
|
Can't Post
|
|
Hi I am a newbie to PHP and I am facing a really weird problem with the "xmlResponse" tags not found error. I have been working on it for the last 5 days and couldnt figure out what the problem is. I would be really grateful if anyone can provide me with the solution to the problem. The following is the code.
$params .= "&method=$method" // Create the request to send to the server $head = "POST /website_api.php HTTP/1.1\r\n"; $head .= "Host: xyz.com\r\n"; $head .= "User-Agent: {$_SERVER['HTTP_HOST']} PHP Script\r\n"; $head .= "Content-Type: application/x-www-form-urlencoded\r\n"; $head .= "Content-Length: " . strlen($params) . "\r\n"; $head .= "Connection: close\r\n\r\n"; // Open a socket connection to the server $socket = @fsockopen('xyz.com', 80, $errno, $errstr, 30); // If there was a HTTP error if (!$socket) die("HTTP error while connecting to Location server: $errstr ($errno)"); // Post the header and the data to the server fputs($socket, $head . $params); // Read the response to a buffer $buffer = ""; while (!feof($socket)) { $buffer .= fgets($socket, 1024); } //die($buffer); fclose($socket); //die($buffer); // Parse the response and get the xml content $p1 = strpos($buffer, "<xmlResponse>"); $p2 = strpos($buffer, "</xmlResponse>"); if ($p1 === FALSE || $p2 === FALSE) die("Could not find xmlResponse tags"); $xmlResponse = trim( substr($buffer,$p1 + 13, $p2 - ($p1 + 13)) ); This code opens a connection to the socket and sends the request to the server listening on website_api.php file where it executes the following code
include shared.php if (strcasecmp($_POST['method'],"GetPage") == 0) { // some code that does the processing for $header_data, $footer_data & $page_data which is simply query and parsing of information from database and it works fine. //Once everything is done it does the following $output = "<content>"; $output .= urlencode($header_data . $page_data . $footer_data); $output .= "</content>"; $sql->FreeAll(); die($XMLHeader . $output . $XMLFooter); } where the XMLHeader & XMLFooter are defined in another file called shared.php
//contents of shared.php $XMLHeader = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?><xmlResponse><response><responsecode>1</responsecode>"; $XMLFooter = "</response></xmlResponse>"; function XMLError($message) { $output = <<<EOB <xmlResponse> <?xml version="1.0" encoding="ISO-8859-1" ?> <response> <responsecode>0</responsecode> <errormsg>$message</errormsg> </response> </xmlResponse> EOB; return $output; } Please anyone who can help me with this issue, I would be really grateful as I have one important deadline based on this issue. Thanks in Advance Hardik
|