Connect to page use method=post (Do not use Form)

Discussion in 'PHP' started by thiendanfc, Sep 29, 2006.

  1. #1
    I want connect to page use method=post but do not use form.
    Ex : I have 2 file is test.html and test.php :
    test.html
    
    <form action='test.php' method=post>
    <input type='hidden' name=test1 value='xxx'>
    <input type='hidden' name=test2 value='xx2'>
    <input type='submit' value='Submit !'>
    
    Code (markup):
    test.php
    
    <?
    echo "test 1 =$_POST[test1] & test 2 = $_POST[test1]";
    ?>
    
    Code (markup):
    When I submit form in test.html, result is :
    Now, I don't use form, I have file post_test.php and I want when I visit this page, it will connect to test.php and post 2 var test1 & test2 (with value can change) and display result is content of test.php page :
    I can use http_post_data http://us3.php.net/manual/en/function.http-post-data.php or http_post_fields: http://us3.php.net/manual/en/function.http-post-fields.php
    But it require install PECL extension http://pecl.php.net/package/pecl_http

    I can't install it in my hosting !

    And about socket ?
    Can you help me ?? I want specific ex . . .

    THANKS !
     
    thiendanfc, Sep 29, 2006 IP
  2. webbist

    webbist Peon

    Messages:
    89
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could use raw sockets, but it would be hard as you'd have to send all the right header information...
     
    webbist, Sep 29, 2006 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I believe that curl will do POSTing... I'd look into using that.
     
    TwistMyArm, Sep 29, 2006 IP
  4. discoverclips

    discoverclips Peon

    Messages:
    491
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you can use fsockopen to POST

    function mailman($email, $subject, $message) {
    $fp = @fsockopen("www.somesite.net", 80, $errno, $errstr, 30);
    $postdata = "email=" . $email . "&subject=" . $subject . "&message=" . $message;
    /* salida goes out */
               $salida ="POST /test.php  HTTP/1.1\r\n";
               $salida.="Host: www.somesite.net\r\n";
               $salida.="User-Agent: PHP Script\r\n";
               $salida.="Content-Type: application/x-www-form-urlencoded\r\n";
               $salida.="Content-Length: ".strlen($postdata)."\r\n";
               $salida.="Connection: close\r\n\r\n";
               $salida.=$postdata;
    /* ------------ */
    
    
    if (!$fp) {
       echo "$errstr ($errno)<br />\n";
    } else {
       fwrite($fp, $salida);
       while (!feof($fp)) {
    $d = fgets($fp);
    
    //echo $d;
    
    
    
    }
    }
    
    
    }
    PHP:
     
    discoverclips, Sep 30, 2006 IP
  5. AlexS

    AlexS Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can try using CURL (this was mentioned above). Here is the documentation (from php.net): us2.php.net/manual/en/ref.curl.php (sorry can't link)
    (To my knowledge most hosts have this enabled.)

    Here is an example:

    
    // Your POST fields "name" => "value"
    $data = array("test1" => "xxx", "test2" => "xx2");
    
    // Curl Usage
    $ch = curl_init();
    
    // Open which page to send post variables?
    curl_setopt($ch, CURLOPT_URL, "http://www.url.com/postform.php");
    
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    
    echo $output; // Lets print our results
    
    PHP:
     
    AlexS, Sep 30, 2006 IP