Dhruv Patel
Dhruv Patel

Reputation: 41

PHP $_REQUEST Sometime empty

$_REQUEST is coming empty sometimes even though log says that $_SERVER['CONTENT_LENGTH'] is non zero.

Below is some of the information from $_SERVER:

[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BTRS125268; .NET CLR 2.0.50727; AskTbARS/5.17.0.25589)
[CONTENT_LENGTH] => 180

Upvotes: 1

Views: 2553

Answers (2)

Abinash Bishoyi
Abinash Bishoyi

Reputation: 185

$_REQUEST is an associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. Whereas $_SERVER is an array containing information such as headers, paths, and script locations. $_REQUEST is a subset of $_SERVER, so it is obvious that though $_REQUEST is empty the $_SERVER is having some content.

Upvotes: 0

rekire
rekire

Reputation: 47965

I expect that the problem is that you post a variable e.g. test and that you have the same variable as parameter in the url. So your $_POST['test'] variable will be overridden by $_GET['test'] and you have the empty value of $_GET['test'] in $_REQUEST['test'].

So better use directly $_GET and $_POST.

Upvotes: 1

Related Questions