您好我正在尝试开发一个 CURL PHP 以首先通过 PHP 发送我的 Google 表单,然后重定向到登录页面。但是,我的问题在于旧的 Google Formkey 响应。
在您可以查看表单源之前,它会有一个表单密钥 ID 号,您可以轻松地将其插入到 PHP 脚本中。
这是我的脚本示例:
//Google Form Key
$formkey = "WHERE IS THE FORMKEY";
$thankyou = "http://www.eksenaevents.com/submission-successful/";
//Change this URL to your google form address
$googleformURL = "https://docs.google.com/forms/d/1pCIHFvau8KuR_J1gSAx2weGcdRGjNH0MERdeinbWd- 0/viewform";
//----------------Send Form Fields to Google--------------------
//Loops through the form fields and creates a query string to submit to google
foreach ($_POST as $var => $value) {
if ($var != "ignore") {
$postdata=$postdata . htmlentities(str_replace("_", "." , $var)) . "=" . $value . "&";
}
}
//remove the extra comma
$postdata=substr($postdata,0,-1);
//Submit the form fields to google
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$googleformURL);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$data = curl_exec ($ch);
curl_close($ch);
//echo $data;
//Redirect to your thank you page
header( "Location: $thankyou" ) ;
?>