Posting with http headers... help!

Discussion in 'PHP' started by sllik, Aug 2, 2007.

  1. #1
    Hi

    I'm trying to post using http headers here is what I got:

    
    $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);
    
    PHP:
    When this code runs, I get a save as "file.php" dialog for some reason.

    I need to post this data and be redirected to $host/$path (just like when a user submits a form).

    Is this possible? How?

    Thanks
     
    sllik, Aug 2, 2007 IP
  2. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #2
    http://curl.haxx.se/mail/curlphp-2006-07/0003.html

    <?php
    $post = Array();
    $post[1] = urlencode('test1');
    $post[2] = urlencode('test2');
    $post[3] = urlencode('test3');
    
    $curl = curl_init("post.php");
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
    $response = curl_exec($curl);
    curl_close($curl);
    
    header('Location: ');
    
    ?>
    PHP:
     
    exodus, Aug 2, 2007 IP