• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

191
Vistas
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?

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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.

almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda