...

View Full Version : php -post to another site



esthera
11-15-2006, 10:21 AM
I want to from my php code hit another server with a post request (not get/querysting) --
can i do this?

I basically have a form that I need to post to php for validation but then i want to send to a different post page (with all of the same values retreived from the form) and then when the post is sent successfully redirect to my success page.

can someone advise me the best way to do this?

SeeIT Solutions
11-15-2006, 01:07 PM
I want to from my php code hit another server with a post request (not get/querysting) --
can i do this?

I basically have a form that I need to post to php for validation but then i want to send to a different post page (with all of the same values retreived from the form) and then when the post is sent successfully redirect to my success page.

can someone advise me the best way to do this?

If you don't just mean setting the form to method=POST and the action to another website then I think it would be best through perl. But I may be wrong. I don't really know how to do it, but that might be a better question to ask.

esthera
11-15-2006, 01:28 PM
no i don't want to do it with the post as it will be after the form is submitted.
I know in asp I would do it as follows:

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", url, false
xmlhttp.send ""
tresponse= xmlhttp.responseText
set xmlhttp = nothing


also is there anyway to pull all the variables from teh post and put it in a string (like with a querysting)

SeeIT Solutions
11-15-2006, 02:07 PM
You'd want curl (i said perl before, oops :confused: ) to do it then.

Something along these lines would do the trick...



$xmlRequest = "<remoteform>".
"<name>".htmlentities( $_POST['name'] )."</name>".
"<password>".htmlentities( $password)."</password>".
"</remoteform>";

/* Use CURL to execute XML POST and write output into a string */
$ch = curl_init( $myURL );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xmlRequest );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 240 );
$xmlResponse = curl_exec( $ch );


Something like that, read up at http://php.net/manual/en/ref.curl.php for more info on what that all does.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum