On Wednesday, February 13, 2002, at 04:04 AM, L. Hoeneveld wrote:
> We use the header() function to display a html page like this:
>
> header("Location: $mail_error_page?CODE=$CODE");
>
> But instead of showing the variable $CODE we would like to hide it.
> Just like
> when you POST variables to a HTML-page. Is there any way to do this?
I see what you're saying -- but the problem is the HTTP protocol
itself. GET data is passed along on the querystring (like you have in
your header function above). POST variables are sent along as
"content", you can look up the official format on the web (google =>
HTTP 1.0 protocol) but basically you have to set up your headers to
describe the fact that you are sending POST data, which are followed by
a blank line (two newlines), then the POST data itself (code=$code).
Just yesterday someone posted a link to the PostToHost function, which
is in the archives. Sorry, I don't have the link, but I recorded the
function -- it is done by opening a socket connection to the server and
communicating directly to it as though it were a file. Here it is:
# ===============================================================
# PostToHost($host, $path, $data_to_send)
# ---------------------------------------------------------------
# "It is a trivial little function."
# -Rasmus
# ===============================================================
function PostToHost($host, $path, $data_to_send)
{
$fp = fsockopen($host,80);
// $fp now points to the "file" opened
by fsockopen
fputs($fp, "POST $path HTTP/1.0\n");
// write the first header, with
the path and the protocol
// (PHP manual annotations suggest using 1.0 over 1.1)
fputs($fp, "Host: $host\n");
// write the hostname line of the header
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
// write
the encoding type line of the header
fputs($fp, "Content-length: " . strlen($data_to_send) . "\n"); //
write
the content-length of data to send
fputs($fp, "Connection: close\n\n");
// close the connection, and a
blank line
fputs($fp, $data_to_send);
// write the data to send (in POST variable
form)
while(!feof($fp)) {
// until the end of the "file", eat 128 bytes
at a time
echo fgets($fp, 128);
}
fclose($fp);
// close the "file"
}
Sorry about the spacing, you'll have to clean it up in your editor. But
I commented the crap out of it so that I'd/you'd understand what was
going on.
HTH,
Erik
----
Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php