Page 1 of 1

How to receive the posting data from ActiveX component?

Posted: Mon May 26, 2003 1:47 am
by calmness
Hello to everybody!

Please help me with the following.
A ActiveX component on the clientside (Msxml2.XMLHTTP) sends the XML data to the PHP script. How to read this data within the PHP code?
It works like CGI script, but I cannot receive anything.
Thanks.

Posted: Mon May 26, 2003 3:56 am
by volka
within the Open-call to your Msxml2.XMLHTTP object you defined the method, e.g.

Code: Select all

xmlhttp.Open("POST", "http://myserver/theScript.php", false);
the string representation of the document should be in $_POST afterwards.
http://www.php.net/manual/en/reserved.v ... ables.post

XMLHTTP to PHP script

Posted: Wed Dec 15, 2004 8:04 pm
by mawrya
Sounds like you want something like the following, which submits a string of xml to a php script on the server, the php then writes the received string into a local file, but you could do anything you want with it. Finally, the php echos a reply back to the html page that sent the xml string and the reply is displayed on the html page.

Running php 5 on apache 2, both files should work as-is if you dump them in the same directory, you could put them on different servers if you like, just be sure to change POST url in the html page - see comment in html code.

Note, the posttest.html code below only works in IE, but Mozilla Browsers have the ability to do XMLHTTP posts just as easily - the info is widely available on the web, just google: mozilla xmlhttp.

over and out, mawrya

======================
CLIENT SIDE HTML - posttest.html
======================

<html>
<head><title>post it pages</title></head>
<body>
<script>
function postXML()
{
//Create string of XML
var sXML="<test>its alive!!</test>";

//Create new XMLHTTP object
var msobj = new ActiveXObject("Microsoft.XMLHTTP");
msobj.open("POST", "posttest.php",false); //Replace "posttest.php" with "http://www.someserver.com/somescript.php" as needed.
msobj.setRequestHeader("Content-Type", "text/xml");
msobj.setRequestHeader("Content-Length", sXML.length);
//Send XML string to PHP script file/url specified on line 12.
msobj.send(sXML);

//Read and display reply from PHP script
var ans = msobj.responseText;
document.getElementById('text1').innerHTML=ans;
}
</script>
<div id=text1></div>
<input type=button value="click me" onclick="postXML()">
</body>
</html>


=====================
SERVER SIDE PHP - posttest.php
=====================

<?php
$sXML = $GLOBALS['HTTP_RAW_POST_DATA'];

// Open a text file and erase the contents if any
$fp = fopen("myXMLfile.xml", "w");

// Write the data to the file
fwrite($fp, $sXML);

// Close the file
fclose($fp);

//Send a reply back to the webpage that submitted the post data.
echo "Document Received Successfully.";
?>

Posted: Wed Dec 15, 2004 8:49 pm
by timvw
i've had some problems with the raw data stuff (didn't exist etc...)

after a long search i ended up with:

Code: Select all

$data = file_get_contents('php://input');