After CURL post I have a double source
For one of my projects I'm creating a registrationform which can be used by other people. In order to make this easy I'm using CURL to send the data. Basically the setup is like this:
A visitor visits registration.php, fills in the form and submits it. In registration.php the user is sen开发者_如何学God to handler.php which is on another webserver. This file commucates with a RegistrationClass and other classes (MySQL, and several models for registering the registration). The RegistrationClass validates the registration based on the gained $_POST-data. This data is returned back to handler.php and gives it back to registration.php.
The only thing is that whenever I submit the form, the validation/registration takes place but the form is rendered twice on the registration.php-page. The first form (the lowest) is the original presentation of the form before submitting. The second is that same form with the validation/registration-result. I'm guessing it's a CURL_OPT I have to set but I can't seem to figure out which one...
This code I'm using to send the user to the handler-page:
if(isset($_POST["ProcessRegistration"]))
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_URL => "http://bfransen.devdev.nl/Global/Willem.php",
CURLOPT_POSTFIELDS => http_build_query($_POST)
)
);
curl_exec($ch);
curl_close($ch);
}
In the RegistrationClass this is to return the values:
private function PostBack()
{
$ch = curl_init();
$this->_POST["Error"] = $this->ErrorCode;
$this->_POST["ErrorMessage"] = $this->GetError($this->ErrorCode);
$this->_POST["Ack"] = true;
unset($this->_POST["ProcessRegistration"]);
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_URL => $this->_SuccessURL,
CURLOPT_POSTFIELDS => http_build_query($this->_POST)
)
);
if(!curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
}
If you try to visit: http://www.fransenmedia.nl/registratie.php and try to use the form, no matter what you fill in, an error will be returned at this moment. But the double form will appear.
P.s. note that I'm Dutch and the files described are named different (registration.php -> registratie.php and handler.php -> Willem.php)
精彩评论