Why Is $_Request Empty

why is $_REQUEST empty

Also try check "request_order" option in php.ini:

; This directive determines which super global data (G,P,C,E & S) should
; be registered into the super global array REQUEST. If so, it also determines
; the order in which that data is registered. The values for this directive are
; specified in the same manner as the variables_order directive, EXCEPT one.
; Leaving this value empty will cause PHP to use the value set in the
; variables_order directive. It does not mean it will leave the super globals
; array REQUEST empty.
; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order = "GP"

Form with POST method returns $_REQUEST but $_POST is empty

I did some further testing on this, trying to simplify the code and duplicate the problem. The code is on a site that has various 'includes'. So I took my simple code (just a form and then print_r of the $_GET/POST/REQUESTs) to help duplicate the problem.

My includes include these statements to sanitize all inputs:

$_POST = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
$_GET = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

Looks OK, doesn't it? Standard sanitize of the $_GET and $_POST variables. Nothing to see here. Move along.

But look more closely. I've used these statements in my code lots of times. Kept going. But it should be this:

$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);

Note that the first block is filtering the GET into POST, and the POST into GET. Dyslexic code!

I call that a "SAF" error - "Smack Against Forehead". Or "LCG" - "Look Closely, Grasshopper".

<sigh> Thanks for the help.

Why $request is empty when I send post request to Laravel from C# App?

json_encodeing $request (or request()) doesn't display - (private) or # (protected) properties, only + (public). See this php artisan tinker example:

>>> request()
=> Illuminate\Http\Request {#70
+attributes: Symfony\Component\HttpFoundation\ParameterBag {#75},
+request: Symfony\Component\HttpFoundation\ParameterBag {#72},
+query: Symfony\Component\HttpFoundation\ParameterBag {#77},
+server: Symfony\Component\HttpFoundation\ServerBag {#79},
+files: Symfony\Component\HttpFoundation\FileBag {#73},
+cookies: Symfony\Component\HttpFoundation\ParameterBag {#76},
+headers: Symfony\Component\HttpFoundation\HeaderBag {#80},
}

As you can see, in Terminal access, it's only showing + (public) properties. Compare with dd(request()) (which shows all properties, regardless of access level):

>>> dd(request())
Illuminate\Http\Request^ {#70
#json: null
#convertedFiles: null
#userResolver: null
#routeResolver: null
+attributes: Symfony\Component\HttpFoundation\ParameterBag^ {#75
#parameters: []
}
+request: Symfony\Component\HttpFoundation\ParameterBag^ {#72
#parameters: []
}
+query: Symfony\Component\HttpFoundation\ParameterBag^ {#77
#parameters: []
}
+server: Symfony\Component\HttpFoundation\ServerBag^ {#79
#parameters: array:132 [...]
}
+files: Symfony\Component\HttpFoundation\FileBag^ {#73
#parameters: []
}
+cookies: Symfony\Component\HttpFoundation\ParameterBag^ {#76
#parameters: []
}
+headers: Symfony\Component\HttpFoundation\HeaderBag^ {#80
#headers: array:5 [...]
}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: null
#requestUri: null
#baseUrl: null
#basePath: null
#method: null
#format: null
#session: null
#locale: null
#defaultLocale: "en"
-preferredFormat: null
-isHostValid: true
-isForwardedValid: true
pathInfo: "/"
requestUri: "/"
baseUrl: ""
basePath: ""
method: "GET"
format: "html"
}

So, when you run json_encode($request), it converts that instance of Illuminate\Http\Request to json, but since most properties are # (protected) or - (private), a lot is stripped out. And even then, for the displayed properties, the only nested property is #parameters, which is protected, and thus stripped out.

So, json_encode(request()) produces the correct JSON:

{"attributes":{},"request":{},"query":{},"server":{},"files":{},"cookies":{},"headers":{}}


Related Topics



Leave a reply



Submit