user2212461
user2212461

Reputation: 3263

$_POST empty in PHP file but call it with POST variables in the URL

I call my php file in the browser with "...test.php?text=Hello" but the $_POST variable stays empty (also print_r($_POST) returns array() ).

Why? Do I need to activate the post variable or something?

Thanks.

Upvotes: 0

Views: 964

Answers (3)

DaveyBoy
DaveyBoy

Reputation: 2924

...test.php?text=hello passes data via the GET method (accessible via $_GET in the processing script).

$_POST gets populated by forms or cURL access (when the transfer method is defined as "post")

Upvotes: 0

Morne
Morne

Reputation: 1743

If you pass the variable through the URL you use $_GET. Also, you will access the variable with:

$_GET['text']

This is a array that is sent through and you need to specify what item in the array you want to use.

Upvotes: 0

Jon
Jon

Reputation: 437664

Variables passed in through the URL end up inside $_GET, not $_POST.

$_POST contains variables parsed by reading the HTTP request body when the method is POST. In this case the method is not POST and there is also no request body.

Upvotes: 2

Related Questions