Jump to content

Do I need to use sockets?


denoteone

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

}
?>


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.