tags:

views:

22

answers:

2

Ok, I've checked the other questions similar to this one, and none seem to point out to a solution to my problem. I have the following code:

<?PHP
$tamanho = $_REQUEST['tamanho'];

$post_data['item_quant'] = $_REQUEST['item_quant'];
$post_data['email_cobranca'] = $_REQUEST['email_cobranca'];
$post_data['tipo'] = $_REQUEST['tipo'];
$post_data['moeda'] = $_REQUEST['moeda'];
$post_data['item_id'] = $_REQUEST['item_id'].$tamanho;
$post_data['item_descr'] = $_REQUEST['item_descr'].'%20Tamanho%20'.$tamanho;
$post_data['item_valor'] = $_REQUEST['item_valor'];
$post_data['peso'] = $_REQUEST['peso'];
$post_data['encoding'] = $_REQUEST['encoding'];
$post_data['submit_01'] = $REQUEST['submit_01'];

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "[erased for security]");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$result = curl_exec($curl);
curl_close($curl);

header('Location:[erased for security]');
?>

It is a barebone code to send a post request to another website, after I modified the product ID and description a little, to make them more unique (so I don't have to create a different product for each color and size of the clothes). However, this arrives at the other page as an empty $_POST array. Location headed is the same location the post request is being sent to.

No errors are being informed at the $result variable.

The output of curl_getinfo($curl) shows the array being sent perfectly.

Environment is PHP 5, and library being used is php_curl.dll.

Something is happening between page A sending the array and page B receiving the array, and I am out of ideas. Can someone help me here, please?

+1  A: 

I had this issue once with CURL I did not dive in too deep to figure out why it happed (probably some issue with the CURL LIB used). I found a workaround by using http_build_query on my array

MANCHUCK
+1  A: 

However, this arrives at the other page as an empty $_POST array. Location headed is the same location the post request is being sent to.

Wait a minute? Are you trying to send someone to a page you just posted to? You cannot do that, the redirect of the user would result in the user / browser/ user-agent doing a GET request no matter what you are posting earlier. What do you see if you echo $result; instead of redirect? Does that page have the correct data? Then curl just plain works. If you want to get the user there with a post, you'll have to echo some sort of form, and perhaps perform some javascript magic to let it immediately submit to your target URL.

Wrikken
I see nothing at the echo $result. It is empty, as well. What I am trying to do is to modify two of the form fields using PHP, before sending the data to where it is suposed to be sent, and then, redirect the user there. Do you mean that because I am using the header command, the browser will always do a get?
Leahn Novash
Yes, that's exactly what I mean. You cannot let the users browser do a post with PHP (but you can post yourself using cURL naturally). If you control both sites, you might want to look into storing a post from the server in a session with a token, and redirect the user with that token in the URL, so you can easily retrieve the previously posted data.
Wrikken