EN VI

PHP $_GET is removing special characters from the value

2022-12-11 20:32:32

I am sending an HTTP GET request with urlencoded value from a client application and on the server side I am using $_GET["Value"] to grab the value.

this is what the request looks like on the client side https://example.com/validate.php?Value=+MqZjrRvtvFdcC3GCRRnnQ== but on the server side the result of $_GET["Value"] is MqZjrRvtvFdcC3GCRRnnQ== without + in the beginning of MqZjrRvtvFdcC3GCRRnnQ== How can I grab the value as it is including all the special characters(if any)

I tried htmlspecialchars($_GET["Value"]) but this didnt work either.

Solution:

The + is a special char which will be escaped by parse_str(). You need to parse the query string by yourself.

Note: If there are multiple values you need to split by & first.

Calling

http://localhost:4000/?Value=+MqZjrRvtvFdcC3GCRRnnQ==

[$key, $value] = explode('=', $_SERVER['QUERY_STRING']);

will give a $value of

+MqZjrRvtvFdcC3GCRRnnQ==
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login