Help Me Get This POST Data Script Working

Discussion in 'PHP & Perl' started by gimme4free, Sep 12, 2009.

  1. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,948
    Likes Received:
    1,949
    I found this on php.net as an example and the user said that it was working for him but it is just spitting back a download prompt for me.

    I am sure that this script would be of a lot of use to a lot of coders if somebody could get it working if it is possible:

    Code:
    <?php
    $host = "www.example.com";
    $path = "/path/to/script.php";
    $data = "data1=value1&data2=value2";
    $data = urlencode($data);
    
    header("POST $path HTTP/1.1\r\n" );
    header("Host: $host\r\n" );
    header("Content-type: application/x-www-form-urlencoded\r\n" );
    header("Content-length: " . strlen($data) . "\r\n" );
    header("Connection: close\r\n\r\n" );
    header($data);
    ?>
     
  2. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    This code is only sending request to browser not to server.
    With PHP you cant force browser to send any POST request...
     
    • Thanks Thanks x 1
  3. xhpdx

    xhpdx Regular Member

    Joined:
    Sep 21, 2008
    Messages:
    331
    Likes Received:
    2,160
    Occupation:
    Coder
    Location:
    EU
    so this is supposed to submit a form i'm guessing. why not use curl to do that or fputs ?
     
  4. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    With fputs or curl you always get same IP adress (server IP). Thats why curl/fputs/fsock etc are not good idea for this things

    regards
    Cyklotrial
     
    Last edited: Sep 13, 2009
  5. iPwnJ00

    iPwnJ00 Junior Member

    Joined:
    Mar 10, 2009
    Messages:
    132
    Likes Received:
    21
    Location:
    Melbourne, Australia
    Shouldn't the line:
    Code:
    header("POST $path HTTP/1.1\r\n" );
    
    be.....

    Code:
    header("POST " . $path . " HTTP/1.1\r\n" );
    
     
  6. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    It will output the same :)
     
  7. 00CivicEX

    00CivicEX Regular Member

    Joined:
    Mar 3, 2009
    Messages:
    294
    Likes Received:
    214
    As cyklotrial said, php is server based, but u can do this with Javascript and if you need it in php just use echo.
     
  8. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,948
    Likes Received:
    1,949
    I was a non-looking for a non-javascript alternative for posting data without using the servers IP address, haven't found a way yet though, not too sure if it is possible without the users input.