Re: POST on redirects?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Lynch wrote:
On Fri, July 28, 2006 3:55 pm, Tony Di Croce wrote:
In a couple of my scripts, I do something like the following when I
detect
an improperly submitted form:

**    if( !valid_string( $_POST['firstname'] ) )
    {
      $return_url =
"https://www.abc.com/checkout_phase1.php?error=FirstName Required";
      header( "location: $return_url" );
      exit(0);
    }

Recently I changed the code so that a big variable that was being
passed via
GET (IE, as a param in the URL) is instead being POST'd... (typically,
via a
hidden INPUT elem in a form)...

Unfortunatley, this broke my error handling logic... Is it possible to
add
POST variables to a redirect? How?

There are functions "out there" to send POST data from PHP.

The canonical example can be found by Googling for "Rasmus Lerdorf
posttohost"


I have a function I use for doing POST transactions in PHP 4. Note that the function just returns the text to send, another function does an fwrite elsewhere. I'm also replacing some of my variables with hardcoded values here to simplify the example, you can fix that as you will:

function make_post($message)
{
	$headers .= "POST /foo.php HTTP/1.1\r\n";
	$headers .= "Host: bar.com\r\n";
	$headers .= "Content-Type: application/octet-stream\r\n";
	$headers .= "Connection: keep-alive\r\n";
	$headers .= "Content-Length: " . strlen($message) . "\r\n";
	$headers .= "\r\n";
	return $headers . $message;
}

As far as I can tell, these are the absolute minimum set of headers you can get away with for a POST transaction (If you know how to use less, let me know, I use this in a situation where overhead matters).

Regards, Adam Zey.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux