Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PHP automatically do urldecode() on $_POST?

According to http://php.net/manual/en/function.urldecode.php, PHP does urldecode() on $_GET and on $_REQUEST (which contains $_POST).

But is directly calling $_POST already decoded?

like image 647
Ethan Allen Avatar asked Feb 19 '16 23:02

Ethan Allen


People also ask

Does PHP automatically decode URL?

PHP | urldecode() FunctionThe urldecode() function is an inbuilt function in PHP which is used to decode url which is encoded by encoded() function. Parameters: This function accepts single parameter $input which holds the url to be decoded. Return Value: This function returns the decoded string on success.

How can I get Urlencode in PHP?

PHP | urlencode() Function. The urlencode() function is an inbuilt function in PHP which is used to encode the url. This function returns a string which consist all non-alphanumeric characters except -_. and replace by the percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

What is Urlencode and Urldecode in PHP?

This is a type of encoding-decoding approach where the built-in PHP functions urlencode() and urldecode()are implemented to encode and decode the URL, respectively. This encoding will replace almost all the special characters other than (_), (-), and (.) in the given URL.

What is Urldecode?

UrlDecode(String) Converts a string that has been encoded for transmission in a URL into a decoded string. UrlDecode(Byte[], Encoding) Converts a URL-encoded byte array into a decoded string using the specified decoding object.


1 Answers

Yes, all the parameters you access via $_GET and $_POST are decoded.

The reason the urldecode() documentation doesn't mention $_POST is because the POST data might not be URL-encoded in the first place. It depends on whether the POST data is submitted in application/x-www-form-urlencoded format or multipart/form-data format.

But all this is transparent to the application.

The documentation of $_GET does mention this explicitly, though.

Note:
The GET variables are passed through urldecode().

like image 139
Barmar Avatar answered Oct 06 '22 00:10

Barmar