我在网站上查找了这个问题的答案,但没有找到我需要的东西(这很接近,除了它实际上没有提交表单:防止表单重定向或提交时刷新? https://stackoverflow.com/questions/1263852/prevent-form-redirect-or-refresh-on-submit).
我正在尝试将邮件列表注册(从 ReverbNation 上托管的注册页面借用的代码)合并到网站中。
表单提交正确,但签名者被重定向到 ReverbNation 网站上呈现的丑陋页面。我无法修改他们的脚本,也不认为有 API 可以用来保持事情整洁。
有没有办法可以在后台提交表单,而无需重定向用户?
以下是 PHP 中用于隧道 POST 的示例。
//set POST variables
$url = 'http://domain.com/url-to-post-to';
$fields = array(
// Add the fields you want to pass through
// Remove stripslashes if get_magic_quotes_gpc() returns 0.
'last_name'=>urlencode(stripslashes($_POST['last_name'])),
'first_name'=>urlencode(stripslashes($_POST['first_name'])),
'email'=>urlencode(stripslashes($_POST['email']))
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
// returns the response as a string instead of printing it
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
echo $result;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)