Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get http url parameter without auto decoding using PHP

Tags:

http

php

get

I have a url like

test.php?x=hello+world&y=%00h%00e%00l%00l%00o

when i write it to file

file_put_contents('x.txt', $_GET['x']); // -->hello world
file_put_contents('y.txt', $_GET['y']); // -->\0h\0e\0l\0l\0o 

but i need to write it to without encoding

file_put_contents('x.txt', ????); // -->hello+world
file_put_contents('y.txt', ????); // -->%00h%00e%00l%00l%00o

how can i do?

Thanks

like image 898
user1725661 Avatar asked Mar 21 '13 05:03

user1725661


People also ask

Does PHP automatically decode URL?

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

How encrypt URL 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.

How decrypt URL in PHP?

The 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.

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

You can get unencoded values from the $_SERVER["QUERY_STRING"] variable.

function getNonDecodedParameters() {
  $a = array();
  foreach (explode ("&", $_SERVER["QUERY_STRING"]) as $q) {
    $p = explode ('=', $q, 2);
    $a[$p[0]] = isset ($p[1]) ? $p[1] : '';
  }
  return $a;
}

$input = getNonDecodedParameters();
file_put_contents('x.txt', $input['x']); 
like image 160
Paul Avatar answered Oct 20 '22 22:10

Paul