0

I have a PHP script in my server that redirects the page using Location: $url entry in header.

But, the request header is not being transmitted to $url.

I see a minimum header defined with User-Agent, Connection, etc.

Let's suppose that I customize some header parameters. I would like to transmit them after redirection.

Is it possible? I would not like to use CURL for that.

jcfaracco
  • 853
  • 2
  • 6
  • 21
  • It would be good to know what you're trying to achieve (maybe there's a better way?). Generally, headers don't persist between requests and responses. Obviously you can copy them from the request and set them on the response, when server-side, but you can't control the behavior of the clients (unless you own the client). – matb Dec 04 '19 at 06:12
  • @matb I'm trying to keep Cookie entry. I know that it is being added by Server side `setcookie` but I would like to use this Cookie on a cross-domain. – jcfaracco Dec 04 '19 at 13:53
  • you can set cookie on *.example.com but can't set cookies cross-domain otherwise. You might want to re-phrase your question or create a new more-specific question. – matb Dec 04 '19 at 22:38
  • @matb thanks for your reply. I will create a new one. Specially because it was marked as duplicated. – jcfaracco Dec 05 '19 at 02:55

1 Answers1

1

This would be up to your HTTP client (web browser or API client?) not your web server. The request headers are, hint, the responsibility of the HTTP client. Your HTTP response with the Location header is the equivalent of your server strongly suggesting the HTTP client try again to the new location.

If you're using cURL, you can use the -L param, as in the following example:

$ curl -L [url]

This tells cURL to follow redirects, and there's a good write up of its usage on this blog post.

developerjack
  • 1,173
  • 6
  • 15