get http url parameter without auto decoding using PHP

后端 未结 3 935
不思量自难忘°
不思量自难忘° 2021-02-15 14:34

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[         


        
3条回答
  •  暖寄归人
    2021-02-15 14:53

    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']); 
    

提交回复
热议问题