0

I have to connect to two scripts on the same endpoint which does not support CORS. I now want to put small PHP script(s) on my own server which execute the HTTP requests server-side to circumvent the browser's CORS issue.

The first script takes a POST request (login) and returns session cookies and a JSON answer.
The second script takes a post request and the session cookies and returns a JSON answer.

I got this working for a POST request that does not require a session cookie, but it does not work where cookies are required. I don't find how I can process the cookie.

How can I get from PHP the cookie returned by the foreign server and process it? How can I send it again with the second request?

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • 1
    I'd suggest looking into CURL or the Guzzle Project, you'll get clear control of cookies and headers with those. With curl, I'd be trying to get them out of the raw headers. the "cookie jar" stuff isn't ideal in my mind. – Scuzzy Aug 11 '17 at 08:25
  • 1
    for the first request http://php.net/manual/en/reserved.variables.httpresponseheader.php then follow it up with https://stackoverflow.com/questions/3431160/php-send-cookie-with-file-get-contents – Scuzzy Aug 11 '17 at 08:49

0 Answers0