2 Replies - 7391 Views - Last Post: 07 October 2010 - 08:07 AM Rate Topic: -----

#1 andwilley  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 50
  • Joined: 18-June 09

POST variables with PHP header()

Posted 07 October 2010 - 07:47 AM

Hey, I need to send some POST variables when I redirect with PHP header() function. I know that GET variables can just be passed in the url, but not sure how to do it with POST. I understand the makeup of the HTTP header, just not how to use PHP header() to send POST variables. Any thoughts?
Is This A Good Question/Topic? 0
  • +

Replies To: POST variables with PHP header()

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,623
  • Joined: 08-June 10

Re: POST variables with PHP header()

Posted 07 October 2010 - 08:02 AM

that’s not possible. a HTTP header (that’s what the header() function sends) does not contain data, not even GET data. the GET data are constructed by PHP.

for this to understand, you should make clear what a header redirect does.

- the client (original file) sends a HTTP request (headers and body)
- the server processes the request sends back a HTTP response containing the redirection header (headers and body)
- the client evaluates the server’s response. it aborts loading the content* and makes a new HTTP request using the URL given in the location header field (header).
- the second server (which may be the same as the first one) receives the request and processes it accordingly

* - this is the important part, as POST data are part of the message body, not the message header

however, you can pass POST data using socket connections or the cURL library. bear in mind that this is a server to server connection.

This post has been edited by Dormilich: 07 October 2010 - 08:04 AM

Was This Post Helpful? 1
  • +
  • -

#3 andwilley  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 50
  • Joined: 18-June 09

Re: POST variables with PHP header()

Posted 07 October 2010 - 08:07 AM

Thanks for the reply. Solved the problem by just inventing a GET variable and sending it with the PHP header() redirect like this:

header ('Location: www.example.com/?confirm=1')


pretty simple. Thanks for your time.

This post has been edited by andwilley: 07 October 2010 - 08:08 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1