Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
How do I pass cookies from a PHP proxy server to a webpage?

I have a webpage consisting of HTML/CSS/JS/JQUERY on server 1.

On server 2, I have a PHP file to avoid cors.

So, I make requests from server 1 to server 2. The PHP code then uses cURL to interact with API I am working with.

This API sends back cookies, which I want to forward back to server 1 ( the website).

I've been searching for a while, but I have no idea how to go about doing this?

I'm guessing it has to do with something to catch the response headers?

Any help would be nice! I'm new to PHP.

Heres more info:

// Here is how I am calling the server 2 file.
$.ajax({
            URL:"HTTP://localhost......server.php",
            type:"post",
            data: $(this).serialize(),
            success: .....,
        });

Is there any way I can just get the headers in this file regularly? Eg. Make it automatically set the cookies here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understand this question correctly. You are hosting a website, and the website makes a request to a PHP script that in turn calls an API that returns some set-cookie headers.

For the cookies to be passed on to the client viewing the website, you'd need to extract the cookie values and call PHPs setcookie function before returning the response to the client from PHP.

Most frameworks will provide a mechanism to specify the header for the response to the client and provide the ability to set a cookie.

Based on your update:

// Here is how I am calling the server 2 file.
$.ajax({
            URL:"HTTP://localhost......server.php",
            type:"post",
            data: $(this).serialize(),
            success: .....,
        });

So you have some JS that is making a request to the "server 2" file. This "server 2" file should be able to extract the values from the response to the curl call it is making and return set-cookie headers to the client. The client will then store those cookies and could provide them on subsequent requests to http://localhost, for how long, for what paths etc are configurable as part of the process for creating the cookie.

Might be worth posting more code, or making it clearer what you aim is with this as there may be a better solution outside of extracting cookie data from the curl call and passing back to the client.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!