drumhrd Posted October 7, 2009 Share Posted October 7, 2009 Ok so here is the deal. basically I have a .com that hosts my production web site (hosting service) and a .net that is inhouse for manufacturing. I need to be able to send data from my web service to my inhouse and visa versa. I figured XML was the best way..seeing that linking up DBs across the internet is a..well..I should just be shot. basically I need to send xml via HTTPS. I have searched and searched and found simpleXML, and xml_rpc. but no good instructions on how to do what I need to do. example. When a new user account is setup on web server. I need to share that information with my manufacturing DB as well. So I want to send this data to my manufacturing end at the same time as I do my DB write on the web side. same thing for when an order is placed..I need to update my DB on the web side and send some XML to tell my manufacturing side that the order can now go into production. I setup a xml $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <account> <username>" . $_POST['username'] . "</username> <login_type>" . $_POST['login_type'] . "</login_type> <firstname>" . $_POST['first_name'] . "</firstname> <lastname>" . $_POST['last_name'] . "</lastname> <address>" . $_POST['address'] . "</address> <address2>" . $_POST['address2'] . "</address2> <city>" . $_POST['city'] . "</city> <state>" . $_POST['state'] . "</state> <country>" . $_POST['country'] . "</country> <zip>" . $_POST['zip'] . "</zip> <email>" . $_POST['email'] . "</email> </account>"; And that's about as far as I can get. I have tried the following but can't get it to work (I am just wanting to see a request hit the other server for now. I'll deal with actually doing something with the XML once I get that far) $url = "https://my_secure_site.com/account_collector.php"; $req =& new HTTP_Request2($url); $req->setHeader("Content-Type", "text/xml"); $req->setHeader("Content-Length", strlen($xmltext)); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->setBody($xmltext); $req->sendRequest(); So I really need some help. I need to be able to take XML formatted data, send it , then be able to take that info on the other end and break it down take the contents of the XML and stuff it into an array so I can use it for DB updates. Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/ Share on other sites More sharing options...
worldcomingtoanend Posted October 7, 2009 Share Posted October 7, 2009 I am not sure if this will help u but i think u r talking of HTTP POST and if thats what u r asking then u need to use some sockets to connect to the main server then send your xml file using php. more or less like the code below after which u need to create other functions like startElement() endElement(), characterData then u do an xml parse, etc: function sendRequest ($request,$host,$port) { // +++++++ initiate connection // $socket = fsockopen($host, $port, $errno, $errstr); if (!$socket) { die("<br>$errno - $errstr<br>"); } // +++++++ Request // $httpRequestLine = "post /xml http/1.1\n"; $httpHeader = "content-length: "; $contentLength = strlen($request); $httpRequest = $httpRequestLine . $httpHeader . $contentLength . "\n\n" . $request; fputs($socket, $httpRequest, strlen($httpRequest)); i hv used the method above to create a search engine whereby the php will create sockets and then i send my xml file via a socket which communicates with the search engine component resident on the server...that way i hv been able to do OTHER applications without necessarily using a database. good luck and sorry if i didnt answer your question. Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/#findComment-932199 Share on other sites More sharing options...
Zane Posted October 7, 2009 Share Posted October 7, 2009 I figured XML was the best way..seeing that linking up DBs across the internet is a..well..I should just be shot. What exactly made you choose XML over a database connection again? If you own the server(s) then there should be no problem connecting the two. Even if it is two servers.. simply allow one to connect to the other...and it's as simple as mysql_connect("hostsite.com",'username','password') or mysql_connect("inhouse.net",'user','pass'); Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/#findComment-932200 Share on other sites More sharing options...
drumhrd Posted October 7, 2009 Author Share Posted October 7, 2009 WWW servers are hosted...inhouse manufacturing servers are owned by us..so ya..I can't make a db connection via the WWW Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/#findComment-932202 Share on other sites More sharing options...
drumhrd Posted October 7, 2009 Author Share Posted October 7, 2009 Ok so I made a test file using the method you suggested. I got it worked out to not have any errors with the script. but it doesn't work <?php function sendRequest ($request,$host,$port) { // +++++++ initiate connection // $socket = fsockopen($host, $port, $errno, $errstr); if (!$socket) { die("<br>$errno - $errstr<br>"); } // +++++++ Request // $httpRequestLine = "post /xml http/1.1\n"; $httpHeader = "content-length: "; $contentLength = strlen($request); $httpRequest = $httpRequestLine . $httpHeader . $contentLength . "\n\n" . $request; fputs($socket, $httpRequest, strlen($httpRequest)); } $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <account> <username>xml_test_user</username> <login_type>0</login_type> <firstname>test</firstname> <lastname>user</lastname> <address>322 someplace drive</address> <address2>box 302</address2> <city>testcity</city> <state>Oklahoma</state> <country>United States</country> <zip>74048</zip> <email>drumhrd@yahoo.com</email> </account>"; sendRequest($xmltest, "ssl://www.mydomain", "443" ); ?> I ran tcpdump on my test server and do not see anything being sent. Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/#findComment-932244 Share on other sites More sharing options...
drumhrd Posted October 7, 2009 Author Share Posted October 7, 2009 ok so I changed sendRequest($xmltest, "ssl://www.mydomain", "443" ); to sendRequest($xmltest, "www.mydomain", "443" ); and it started working..I see that I am sending data out my server interface I see the data being sent. Now I just have to figure out how to read it on the other side. Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/#findComment-932261 Share on other sites More sharing options...
worldcomingtoanend Posted October 7, 2009 Share Posted October 7, 2009 sorry was out for a moment...is it working now..if so then, i am happy for you...once again as long as you master 1). opening ports with php 2). startelement() 3). endElement() 4). characterData() 5). xml parsing() u will solve your problem and by the way all those functions can go in the same php file, at least thats what i usually do. before i forget make sure also that the target port is open otherwise your socket connections will not work. u can test an open port by using this script <?php $port = "3000"; //----localhost or url $host = "localhost"; $socket = fsockopen($host, $port, $errno, $errstr); if (!$socket) { echo "socket failed to open"; }else { echo "socket is opened for you!!!!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/#findComment-932278 Share on other sites More sharing options...
drumhrd Posted October 7, 2009 Author Share Posted October 7, 2009 I can get the xml request to go user port 80..but I would like to see this encrypted and sent via 443..any idea how to do that? Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/#findComment-932289 Share on other sites More sharing options...
drumhrd Posted October 7, 2009 Author Share Posted October 7, 2009 so yes I have been able to successfully send the xml data across port 80. I have attempted the port 443 without any luck. I would assume there is a way to transport this securely correct?? Quote Link to comment https://forums.phpfreaks.com/topic/176802-solved-xml-madness/#findComment-932311 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.