Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda