0

I am using the following code to automatically fill in a field and submit a form at another server:

<?php   
    include "Snoopy.class.php";
    $snoopy = new Snoopy;      
    $snoopy->agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 FirePHP/0.2.1";
    $snoopy->referer = "http://www.google.com/";
    $url = "http://example.com/?page=a";
    $data["field_name"] = "value";
    $snoopy->httpmethod = "POST";
    $snoopy->submit($url, $data);
    echo $snoopy->results;
?> 

The problem is that it does not work!

The source of the page http://example.com/?page=a is:

<form action="" method="post" class="horizontal-form" role="form" >
<input type="hidden" name="submit_form" value="true" />
<input type="text" name="field_name" class="form-control" value="" >
<button type="submit" class="btn"><i class="icon-ok"></i> Send</button>
</form>

Any idea how it can be fixed? Can it be that the "action" in the main page is empty?

Thank you for your help.

cybergeek654
  • 290
  • 1
  • 5
  • 15
  • Do you have any control over the page that you are posting too? – Cave Johnson May 30 '15 at 00:54
  • What kind of response do you get? Are there any errors? Are there any php errors in your php after you add `ini_set('display_errors', '1');error_reporting(E_ALL);` to the top? One thing that comes to mind is that they block requests based on the referer. Maybe you can try changing it to match the url of the form page. – Cave Johnson May 30 '15 at 01:05
  • @Andrew, thanks for the reply. No I do not have any control over the page I am posting to. After running my php code, I do not get any errors, even after adding the code you provided. I changed the referrer to be same as the target page url, still does not work. – cybergeek654 May 30 '15 at 08:02
  • After running the code, the "results" contain the html code of the target page, exactly as it is on the target website. This is not good, because if the POST was successful, the result page should have contained one div saying that "field_name" was incorrect format or that submission was successful. – cybergeek654 May 30 '15 at 08:06

0 Answers0