denoteone Posted September 9, 2010 Share Posted September 9, 2010 I have server #1 that host a php page with a form. I have server #2 that has a VPN connection to #1. I want the user to fill out the form on server #1 and on submit the data is sent to server #2 where it is processed and then an email is sent from server #2 with a confirmation. I do not want the user to be sent to the server#2 though. They can be sent to a thank you page. Can anyone enlighten me with the best function to use in this case or if it is even possible? THANKS Everyone! Quote Link to comment https://forums.phpfreaks.com/topic/212964-do-i-need-to-use-sockets/ Share on other sites More sharing options...
Psycho Posted September 9, 2010 Share Posted September 9, 2010 You can have the form post to a processing page on Server 1. After that page does the necessary validation of the data the processing page would then send the data to a receiving page on Server 2. That page would then do whatever it needs to with the data (e.g. save to a db) then send back a response to the processing page from Server 1. The Server 1 processing page would then either display a success or failure message depending upon the response received from server 2. For sending the data from Server 1 or Server 2 you could either send it by adding the data to the URL (Server 2 would processign the data from the $_GET variable), you could use cURL, or you could even send it via POST. See this page for an example on how you can resend POST data using PHP (I have not tested this myself): http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl Quote Link to comment https://forums.phpfreaks.com/topic/212964-do-i-need-to-use-sockets/#findComment-1109197 Share on other sites More sharing options...
denoteone Posted September 9, 2010 Author Share Posted September 9, 2010 Thanks for the reply mjdamato. What if on submit the page has an isset that checks that the proper data has been entered and then use fsockopen to send the post data to a script on another server. Then this page could wait until that is complete and echo the results? something like: <?php if (isset($_POST['submit'])){ $name = $_POST['name']; $serial = $_POST['serial_num']; $fp = fsockopen("10.10.10.xx/processingscript.php", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { //pass $name & $serial to processingscript.php and then get something back from processingscript.php that says $valid = "yes" or $valid = "no" . while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } echo $vaild } ?> Quote Link to comment https://forums.phpfreaks.com/topic/212964-do-i-need-to-use-sockets/#findComment-1109251 Share on other sites More sharing options...
Psycho Posted September 9, 2010 Share Posted September 9, 2010 Um, sure, use fsockopen() if you want. I'm not sure how you would use it to send the POST data to the processing page on Server 2. I'm sure it can be done, I've just never seen it done in that way. I think you *may* have to build a more complex service on Server 2 to make it work though. I think the solution I provided is much more elegant as you can just repurpose the POST data and send it to Server 2 directly from Server 1 instead of having it come from the user. So the user is not connecting to Server 2 at all. Quote Link to comment https://forums.phpfreaks.com/topic/212964-do-i-need-to-use-sockets/#findComment-1109263 Share on other sites More sharing options...
denoteone Posted September 9, 2010 Author Share Posted September 9, 2010 I think the solution I provided is much more elegant as you can just repurpose the POST data and send it to Server 2 directly from Server 1 instead of having it come from the user. So the user is not connecting to Server 2 at all. I agree and would like to do it that way I am just not sure if I understand how. Am I on the right path? I would set the action in the form to my processing page on Server 1. The process page is just the normal checking to make sure everything was filled out. ***How does the data then get from there to Server 2? And from there I am lost. I guess I dont understand how the pages invoke each other to pass the $_POST data? Quote Link to comment https://forums.phpfreaks.com/topic/212964-do-i-need-to-use-sockets/#findComment-1109309 Share on other sites More sharing options...
denoteone Posted September 9, 2010 Author Share Posted September 9, 2010 After a little more research I am going to assume the best way to send POST DATA Between php scripts is using cURL. Quote Link to comment https://forums.phpfreaks.com/topic/212964-do-i-need-to-use-sockets/#findComment-1109320 Share on other sites More sharing options...
Psycho Posted September 9, 2010 Share Posted September 9, 2010 The page I linked to showed a method to Re-post the data without using cURL. Here is an example of what I proposed (I left a LOT of necessary code out, but this should provide an illustration): Form Page (Server #1) <form action="processing.php" method="POST"> // Form fields go here </form> Processing Page: processing.php (Server 1) if(isset($_POST)) { //Validate the POST data to ensure it is complete if(!$valid) { //Redirect back to form with error message } else { //Resend POST data to Server #2 processing page using function linked to above $result = do_post_request('http://server2/finalprocessing.php', $_POST); if($result!==true) { echo "The following errors occured: $result"; } else { echo "The record has been added"; } } } The page 'finalprocessing.php' would exist on Server #2 and would need to provide a response based on the POST data if(isset($_POST) { //Validate and process the post data. If all goes well echo "true" //else echo an error message. // //The content echo'd will be returned to the processing page on server #1 } Quote Link to comment https://forums.phpfreaks.com/topic/212964-do-i-need-to-use-sockets/#findComment-1109334 Share on other sites More sharing options...
denoteone Posted September 9, 2010 Author Share Posted September 9, 2010 Thanks mjdamato That is exactly what I had in mind. I am not sure why I didnt come across "do_post_request" in my searches. I have already started testing. cURL I guess would be handy if SERVER 2 had ssl enabled. Thanks again for your help. Quote Link to comment https://forums.phpfreaks.com/topic/212964-do-i-need-to-use-sockets/#findComment-1109360 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.