Help Me Get This POST Data Script Working

gimme4free

Elite Member
Joined
Oct 22, 2008
Messages
1,935
Reaction score
1,989
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);
?>
 
This code is only sending request to browser not to server.
With PHP you cant force browser to send any POST request...
 
so this is supposed to submit a form i'm guessing. why not use curl to do that or fputs ?
 
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:
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);
?>

Shouldn't the line:
Code:
header("POST $path HTTP/1.1\r\n" );

be.....

Code:
header("POST " . $path . " HTTP/1.1\r\n" );
 
As cyklotrial said, php is server based, but u can do this with Javascript and if you need it in php just use echo.
 
As cyklotrial said, php is server based, but u can do this with Javascript and if you need it in php just use echo.
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.
 
Back
Top