How to receive the posting data from ActiveX component?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
calmness
Forum Newbie
Posts: 6
Joined: Fri May 23, 2003 8:51 am
Location: Kiev, Ukraine
Contact:

How to receive the posting data from ActiveX component?

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
mawrya
Forum Newbie
Posts: 1
Joined: Wed Dec 15, 2004 8:02 pm

XMLHTTP to PHP script

Post 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.";
?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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');
Post Reply