How to receive data, sent from header(location: .....) on next php page in POST method?

In file1.php I am sending data through this code:

header("Location: file2.php? age=20");

In file2.php I am hoping to get this data through POST…

$age = $_POST['age'];

…But I not getting it. I would like to get data via POST at page2.php.

Any help would be appreciated.

Upvotes: 0

Views: 165

Answers (2)

Jonan
Jonan

Reputation: 2536

It is not possible to send POST data through a redirect. It is, however, possible to send POST data using cURL. See the accepted answer here for an example, and the php documentation for more info

Upvotes: 0

Bernhard
Bernhard

Reputation: 1870

If you call an URL with get-parameters you need to access this parameters also with the $_GET-method.

You access the "age"-parameter in file2.php?age=20 by

$_GET['age']

Here are two links about post and get

http://php.net/manual/en/reserved.variables.post.php http://php.net/manual/en/reserved.variables.get.php

Upvotes: 2

Related Questions