1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trying hard to create a PHP Submition Macro

Discussion in 'General Programming Chat' started by sergbot, Nov 4, 2012.

  1. sergbot

    sergbot Junior Member

    Joined:
    Jan 20, 2010
    Messages:
    172
    Likes Received:
    23
    Basically there is a website where there is a form


    Code:
        <input type="text" class="text" id="_tf11" name="tf[11]" value="0" maxlength="4">
        <input type="image" id="btn_train" class="dynamic_img" value="ok" name="s1"     src="assets/x.gif" alt="Training">
    
    And I wanted to write a program that will fill out the form and resubmit it every 10 minutes. This is what I got, but it doesn't work at all.

    The program:


    Code:
        <?php
        //create array of data to be posted
        $post_data['tf[11]'] = '10000';
        $post_data['s1'] = 'ok';
        //traverse array and prepare data for posting (key1=value1)
        foreach ( $post_data as $key => $value) {
            $post_items[] = $key . '=' . $value;
        }
        //create the final string to be posted using implode()
        $post_string = implode ('&', $post_items);
        //create cURL connection
        $curl_connection =
          curl_init('http://crusadertrav.com/build.php?id=33');
        //set options
        curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($curl_connection, CURLOPT_USERAGENT,
          "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
        curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
        //set data to be posted
        curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
        //perform our request
        $result = curl_exec($curl_connection);
        //show information regarding the request
        print_r(curl_getinfo($curl_connection));
        echo curl_errno($curl_connection) . '-' .
                        curl_error($curl_connection);
        //close the connection
        curl_close($curl_connection);
        ?>
    




    The result:



    Code:
         Array ( [url] => http://crusadertrav.com/index.php [content_type] => text/html; charset=UTF-8 [http_code] => 200 [header_size] => 895 [request_size] => 350 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 1 [total_time] => 2.781 [namelookup_time] => 0 [connect_time] => 0.532 [pretransfer_time] => 0.532 [size_upload] => 0 [size_download] => 10655 [speed_download] => 3831 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.954 [redirect_time] => 0.906 [certinfo] => Array ( ) [primary_ip] => 5.154.88.71 [primary_port] => 80 [local_ip] => 192.168.11.52 [local_port] => 3222 [redirect_url] => ) 0-
    
    help please, Thank you. Posted it on stack overflow but those selfish bastards deemed it too localized and closed it.
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,148
    Those selfish bastards where right because SO is a QA site and your post is not a Q. It 's a "help me do it cause I don't know how to" type, something they do not accept there. SO is a very useful resource when you know how to use it.
     
  3. sergbot

    sergbot Junior Member

    Joined:
    Jan 20, 2010
    Messages:
    172
    Likes Received:
    23
    Well bro, no one is helping me anywhere at all. not even for money.