Server could not capture POST data sent from another server by URL redirection

Recently, I started work on a Payment Gateway (hereinafter referred to as " PG ") for my site. This process involves sending Publish form data to the PG server by redirecting to their page and receiving a response from the PG about the transaction via POST data sent by redirecting the URL to our server page.

The problem arises here because my server cannot receive the POST data sent from the PG server.

Since I'm coding in PHP, I tried to print the whole answer coming from PG with print_r($_POST); and even tried using print_r($_REQUEST); . I did not find print data other than PHPSESSID and some other data array.

Regarding confirmation, I checked whether they sent the data or not with the IE addon known as " TamperIE ". It shows all the sending of POST data to their server. But this is not the way to our server. I tried this process on another server: there I was able to get a POST response, but not with the current working server.

Can you imagine what might be the problem?

+4
source share
4 answers

To simulate a request from another server using curl, do test.php with the following contents:

 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.example.com/path/to/form"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_VERBOSE, true); $data = array( 'foo' => 'foo foo foo', 'bar' => 'bar bar bar', 'baz' => 'baz baz baz' ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); 

And run it with cli to get debugging information and see what is wrong. Remember to output the variables that should be returned from the server, and the exact url

0
source

I found the cause of this problem.

In the .htaccess file, I wrote a line for redirection:

 RewriteRule ^ http://mysite.com{REQUEST_URI} [R=301,L] 

If I delete the above line from a file, I can receive POST fields from the PG server, but I lose the SESSION DATA data stored before the PG started, it contains information about the reservation. These sessions cannot be displayed on the response page because the server generates a completely new session from the response page.

I found one alternative solution to this problem:

I use the following code on all pages that require a session like:

 $lifetime=60*30; session_set_cookie_params ( $lifetime , '/', '.mysite.com'); 

After adding the code above session_start(); .

Now I can get both POST data from PG, and also save SESSION values.

However, I think this is not an ideal solution for this problem. If someone can offer any SERVER configuration for URL redirection and maintain SESSION values ​​after REDIRECTION, that would be great. Thanks to everyone :-)

0
source

If possible, send the unique code (order ID) of your sales / purchase order in the PG request, and I am sure that your PG will send this unique code back to the POST data and using this unique code that you can track this order ID, to update the order status.

Using this approach, you do not need to worry about the session.

0
source

Use CURl for this, its reliability and reliability.

0
source

Source: https://habr.com/ru/post/1439965/


All Articles