PHP Post & Redirect with cURL just like an HTML form

In HTML, we can create a form and enter the input, and then send it as a POST to any destination; This means that we send and redirect at the same time, and the destination discovers as the same. I want to do the same using cURL; So when I use cURL to send data, then I should be able to redirect using something like header (), and the destination behaves similar to how a process runs regularly using an HTML form.

Is it possible to?!

+2
source share
2 answers

What you want to do, I think, looks something like this:

Client --> Server A Server A --> POST --> Server B Client <------------------------ Server B 

so that, for example, a client can access server B without knowing the password that server A knows.

If so , you can do something similar, but not quite what you want (which may be something like OpenID, although it is allowed with OpenID).

You can have server A doing POST and receive a response and send a response to the Client. Unfortunately, you probably cannot set cookies (they will be valid for subdomain A, and they will no longer be sent to server B), and sessions will probably not work for similar reasons.

Perhaps you have server A acting as a full proxy server: see this answer How do I remove the contents of a website in PHP from a website that requires a cookie? .

Payment gateway

Most banks have an API to do just that (Paypal, even this is not a bank, does , and therefore WorldPay ).

One possible workflow is to send all the data to a bank that responds with a unique identifier. Then you either show all the information yourself, or (especially you prefer banks), the bank shows information to customers when you redirect them using a special URL and a unique identifier.

The client can change the data in his form, but all he gets is to abort the transaction, because these two copies of the data are no longer consistent, and he can not touch the copy you sent (other methods and workflows exist).

If your system works in accordance with this document flow (or similar) and uses its own API for the bank and the proposed methods, please ignore and accept my apologies: you are doing it right. But just in case, if not, well, please think about it.

Trying to create your own cURL workflow is probably possible (for some banks it is definitely possible), but is suspiciously close to turning over your own cryptography , it will probably be less supported by the bank, and may cause some abnormal detector on the banking part (just to bring it, a lot of payments, it seems, will come from the same IP address or range).

0
source

Yes, you can have cURL for forwarding using the option:

 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 

From Manual :

CURLOPT_FOLLOWLOCATION

TRUE to follow any "Location:" header that the server sends as part of the HTTP header (note that this is recursive, PHP will follow the many "Location:" headers that are sent if CURLOPT_MAXREDIRS is not set).

+4
source

All Articles