处理回复数据PHP
我创建了这个网站,当访问时自动投票投票。 http://qthostoi.atspace.cc/sdd.php处理回复数据PHP
问题是,当它提交它下载index.php
我不希望这样,我该如何防止?
源代码:
<html>
<body>
<form action="http://recipes.wikia.com/index.php" method="POST" onsubmit="alert(2)">
<input type="hidden" name="title" value="User_blog:Kate.moon/Battle_of_the_Fantasy_Foods-_Round_SIX" />
<input type="hidden" name="action" value="ajax" />
<input type="hidden" name="rs" value="axAjaxPollSubmit" />
<input type="hidden" name="wpPollId" value="B5686B741937166683ACC4DC49C515BB" />
<input type="hidden" name="wpVote" value="Vote!" />
<input type="hidden" name="wpPollRadioB5686B741937166683ACC4DC49C515BB" value="3" />
<input type="submit" value="Submit request" />
</form>
<script>
document.forms[0].submit();
</script>
</body>
</html>
我尝试这些:
1:
<?php
$url = 'http://recipes.wikia.com/index.php';
$fields = array(
'title' => "User_blog:Kate.moon/Battle_of_the_Fantasy_Foods-_Round_SIX",
'action' => "ajax",
'rs' => "axAjaxPollSubmit",
'wpPollId' => "B5686B741937166683ACC4DC49C515BB",
'wpVote' => "Vote!",
'wpPollRadioB5686B741937166683ACC4DC49C515BB' => "3",
);
$count = count($fields);
$fields = http_build_query($fields);
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_POST, $count);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
这做接收响应,并阻止下载,但它没有我的数据提交给其他领域。我认为它提交了错误的数据。
2:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body>
<script>
$("#contactForm").submit(function(event)
{
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $(this),
$submit = $form.find('button[type="submit"]'),
title_value = $form.find('input[name="title"]').val(),
action_value = $form.find('input[name="action"]').val(),
rs_value = $form.find('input[name="wpPollId"]').val(),
wpPollId_value = $form.find('input[name="title"]').val(),
wpVote_value = $form.find('input[name="wpVote"]').val(),
wpPollRadioB5686B741937166683ACC4DC49C515BB_value = $form.find('input[name="wpPollRadioB5686B741937166683ACC4DC49C515BB"]').val(),
message_value = $form.find('textarea[name="message"]').val(),
url = $form.attr('action');
/* Send the data using post */
var posting = $.post(url, {
title: title_value,
action: action_value,
rs: rs_value,
wpPollId: wpPollId_value,
wpVote: wpVote_value,
wpPollRadioB5686B741937166683ACC4DC49C515BB: wpPollRadioB5686B741937166683ACC4DC49C515BB_value
});
posting.done(function(data)
{
/* Put the results in a div */
$("#contactResponse").html(data);
/* Change the button text. */
$submit.text('Sent, Thank you');
/* Disable the button. */
$submit.attr("disabled", true);
});
});
</script>
<form id="contactForm" action="http://recipes.wikia.com/index.php" Method="POST">
<input type="hidden" name="title" value="User_blog:Kate.moon/Battle_of_the_Fantasy_Foods-_Round_SIX" />
<input type="hidden" name="action" value="ajax" />
<input type="hidden" name="rs" value="axAjaxPollSubmit" />
<input type="hidden" name="wpPollId" value="B5686B741937166683ACC4DC49C515BB" />
<input type="hidden" name="wpVote" value="Vote!" />
<input type="hidden" name="wpPollRadioB5686B741937166683ACC4DC49C515BB" value="3" />
<input type="submit" value="Submit request" />
</form>
<div id="contactResponse"></div>
</body>
</html>
它并提交了数据,但下载index.php
任何帮助吗?
你可以用jQuery发布表单并捕获json响应。尝试是这样的:
<html>
<body>
<form action="http://recipes.wikia.com/index.php" method="POST" onsubmit="alert(2)">
<input type="hidden" name="title" value="User_blog:Kate.moon/Battle_of_the_Fantasy_Foods-_Round_SIX" />
<input type="hidden" name="action" value="ajax" />
<input type="hidden" name="rs" value="axAjaxPollSubmit" />
<input type="hidden" name="wpPollId" value="B5686B741937166683ACC4DC49C515BB" />
<input type="hidden" name="wpVote" value="Vote!" />
<input type="hidden" name="wpPollRadioB5686B741937166683ACC4DC49C515BB" value="3" />
<input type="submit" value="Submit request" />
</form>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(function() {
var data = $("form").serializeArray();
$.post('http://recipes.wikia.com/index.php', data, function(jsonResponse){
var jsonObj = $.parseJSON(jsonResponse);
alert("The id: " + jsonObj.id);
});
});
</script>
</body>
</html>
它的仍然弹出下载与'index.php'的框。自己试试 – 2014-09-26 13:48:16
我不能,它是跨域的,你可以在'http:// recipes.wikia.com/index.php'显示代码 – 2014-09-26 13:50:40
你可以在你的计算机上创建一个'index.html'文件与该代码并提交。 (简单)我也无法访问该域名(recepies.wikia.com)。 – 2014-09-26 13:56:09
尽量把你的JavaScript代码$(document).ready(function(){/*your code here*/})
$(document).ready(function(){
/*put your code here*/
$("#contactForm").submit(function(event)
{
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $(this),
$submit = $form.find('button[type="submit"]'),
title_value = $form.find('input[name="title"]').val(),
action_value = $form.find('input[name="action"]').val(),
rs_value = $form.find('input[name="wpPollId"]').val(),
wpPollId_value = $form.find('input[name="title"]').val(),
wpVote_value = $form.find('input[name="wpVote"]').val(),
wpPollRadioB5686B741937166683ACC4DC49C515BB_value = $form.find('input[name="wpPollRadioB5686B741937166683ACC4DC49C515BB"]').val(),
message_value = $form.find('textarea[name="message"]').val(),
url = $form.attr('action');
/* Send the data using post */
var posting = $.post(url, {
title: title_value,
action: action_value,
rs: rs_value,
wpPollId: wpPollId_value,
wpVote: wpVote_value,
wpPollRadioB5686B741937166683ACC4DC49C515BB: wpPollRadioB5686B741937166683ACC4DC49C515BB_value
});
posting.done(function(data)
{
/* Put the results in a div */
$("#contactResponse").html(data);
/* Change the button text. */
$submit.text('Sent, Thank you');
/* Disable the button. */
$submit.attr("disabled", true);
});
});
});
它也下载'index.php' – 2014-09-26 15:59:38
对于迟到的评论。我认为你的代码正在下载index.php,因为你正常发布你的表单,而不是来自'$ .post()'。如果您通过'$ .post()'成功发送表单,请尝试使用萤火虫进行调试。 – 2014-09-28 17:14:51
有没有什么参考喜欢网页的API? (Recipes.wikia.com)或者你只是尝试模拟你的账户投票。我认为你需要为此登录,因此索引 – 2014-09-26 11:56:38
有可能是index.php有问题,你可以请发布代码? – Ashish 2014-09-26 12:03:07
@FrankProvost我想模拟和Recipies.wikia.com不需要登录它只是检查IP地址没有登录 – 2014-09-26 12:13:34