I have an HTML form, being submitted to a PHP page. The PHP page needs to validate a captcha and then pass the form values to a JSP page. I have NO control over the JSP page. Captcha is working beautifully. Something is getting lost in my PHP page, as when it loads the information on the JSP page, the CSS and headers of the target page aren’t loading and the form data isn’t being passed. I do not have access to the JSP page. Any ideas?
BTW, Captcha validation is working fine and the HTML works fine if I pass it directly to the JSP page:
<?php
require_once('recaptchalib.php');
$privatekey = "privatekeyhere";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("<p align='center'>The reCAPTCHA wasn't entered correctly. Please go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")</p>");
} else {
$ipaddress = $_SERVER["REMOTE_ADDR"];
$fname = $_POST['fname'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$h = curl_init();
curl_setopt($h, CURLOPT_URL, "//remote JSP page");
curl_setopt($h, CURLOPT_HEADER, true);
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, array(
'fname' => '$fname',
'address' => '$address',
'city' => '$city',
'state' => '$state',
'zip' => '$zip',
'phone' => '$phone',
'email' => '$email',
));
curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($h);
echo $result;
}
?>
Problems I can spot right away:
CURLOPT_POSTFIELDhas to be a POST string, not an array.For point 1, here’s a simple cUrl tutorial by David Walsh, covering a case very similar to yours and containing a way to transform arrays in POST strings: http://davidwalsh.name/execute-http-post-php-curl
For point 2, strings inside
'single quotes'are not evaluated. To refer to a variable, you should use$var, not'$var'.Bonus: anything in a POST/GET string should be urlencoded.