2014-09-26 55 views
1

我創建了這個網站,當訪問時自動投票投票。 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&#95;blog&#58;Kate&#46;moon&#47;Battle&#95;of&#95;the&#95;Fantasy&#95;Foods&#45;&#95;Round&#95;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&#33;" /> 
     <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&#95;blog&#58;Kate&#46;moon&#47;Battle&#95;of&#95;the&#95;Fantasy&#95;Foods&#45;&#95;Round&#95;SIX", 
     'action' => "ajax", 
     'rs' => "axAjaxPollSubmit", 
     'wpPollId' => "B5686B741937166683ACC4DC49C515BB", 
     'wpVote' => "Vote&#33;", 
     '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&#95;blog&#58;Kate&#46;moon&#47;Battle&#95;of&#95;the&#95;Fantasy&#95;Foods&#45;&#95;Round&#95;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&#33;" /> 
     <input type="hidden" name="wpPollRadioB5686B741937166683ACC4DC49C515BB" value="3" /> 
     <input type="submit" value="Submit request" /> 
</form> 
<div id="contactResponse"></div> 



     </body> 
</html> 

它並提交了數據,但下載index.php

任何幫助嗎?

+0

有沒有什麼參考喜歡網頁的API? (Recipes.wikia.com)或者你只是嘗試模擬你的賬戶投票。我認爲你需要爲此登錄,因此索引 – 2014-09-26 11:56:38

+0

有可能是index.php有問題,你可以請發佈代碼? – Ashish 2014-09-26 12:03:07

+0

@FrankProvost我想模擬和Recipies.wikia.com不需要登錄它只是檢查IP地址沒有登錄 – 2014-09-26 12:13:34

回答

0

你可以用jQuery發佈表單並捕獲json響應。嘗試是這樣的:

<html> 
    <body> 
    <form action="http://recipes.wikia.com/index.php" method="POST" onsubmit="alert(2)"> 
     <input type="hidden" name="title" value="User&#95;blog&#58;Kate&#46;moon&#47;Battle&#95;of&#95;the&#95;Fantasy&#95;Foods&#45;&#95;Round&#95;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&#33;" /> 
     <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> 
+0

它的仍然彈出下載與'index.php'的框。自己試試 – 2014-09-26 13:48:16

+0

我不能,它是跨域的,你可以在'http:// recipes.wikia.com/index.php'顯示代碼 – 2014-09-26 13:50:40

+0

你可以在你的計算機上創建一個'index.html'文件與該代碼並提交。 (簡單)我也無法訪問該域名(recepies.wikia.com)。 – 2014-09-26 13:56:09

0

儘量把你的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); 
     }); 
    }); 
}); 
+0

它也下載'index.php' – 2014-09-26 15:59:38

+0

對於遲到的評論。我認爲你的代碼正在下載index.php,因爲你正常發佈你的表單,而不是來自'$ .post()'。如果您通過'$ .post()'成功發送表單,請嘗試使用螢火蟲進行調試。 – 2014-09-28 17:14:51