CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Other Programming Languages: PHP:
Could not find xmlResponse tags



Feb 2, 2011, 9:44 AM

Post #1 of 1 (49343 views)
Could not find xmlResponse tags Can't Post


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:\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('', 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);
// 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>";


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
<?xml version="1.0" encoding="ISO-8859-1" ?>

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


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives