Problem submitting a POST request "by hand"
| From: | Vallo Reima | Date: | Mon, 28 Feb 2005 11:19:40 +0000 |
| Subject: | Problem submitting a POST request "by hand" | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-209584@lists.php.net to get a copy of this message | ||
Hello!
I send the parameters from one php script to another via POST method. The solution works (see example below) but the receiver page loads ONLY if I include the echo $c; command after send_host (see PROBLEM!!! line). Otherwise a blank page loads without any error messages. The problem is same with Microsoft-IIS/5.1-PHP/5.0.3 and Apache/2.0.51-PHP/4.3.10... What can I do to get rid of this?
Thanks!
Vallo
function send_host($host,$path,$query,$others=''){
$d="POST $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\n${others}User-Agent: Mozilla 4.0\r\nContent-length: ".strlen($query)."\r\nConnection: close\r\n\r\n$query";
if (!$h = fsockopen($host,80)) {
return -1;
}
else {
stream_set_timeout($h,10);
}
if (fputs($h,$d) === FALSE) {
return -2;
}
else {
$r = '';
while(!feof($h)) {
$r .= fgets($h, 128);
}
}
if (fclose($h) === FALSE) {
return -3;
}
else {
return $r;
}
}
/* ... */
$c = send_host("$host_name","$redirect","$par");
if ($c < 0) {
echo "<B>ERROR $c</B>";
} else {
echo $c; /* PROBLEM!!! */
}