Welcome Guest, Not a member yet? Register   Sign In
getVar() behavior on Windows and Linux
#1

(This post was last modified: 12-29-2022, 02:44 AM by ruslan.)

$this->request->getVar("id")  in a controller works for GET request parameters only on my local env - Windows 10 / Apache / PHP8

On Ubuntu 20 / Nginx / PHP8 i get `undefined` for the same request

Replacing it with getGet("id") solves the problem

PHP Code:
return $this->respond([
  "id-get" => $this->request->getGet("id"),
  "id-var" => $this->request->getVar("id"),
  "GET" => $_GET
]); 

Response:

Code:
GET: {id: "1", data: "{"status":"0"}"}
id-get: "1"
id-var: null


Isn't it a bug? Because documentation says: "The getVar() method will pull from $_REQUEST, so will return any data from $_GET, $POST, or $_COOKIE (depending on php.ini request-order)."
Reply
#2

Check the request_order value in phpinfo().
If G is not set, GET values are not set in $_REQUEST.
Reply
#3

request_order GP
Reply
#4

Okay, no problem.
I don't know why you can't get with getVar().

Did you checked the $_REQUEST value?
Reply
#5

(This post was last modified: 12-29-2022, 11:58 PM by ruslan.)

$_REUEST is empty


Code:
"id-get": "22",
"id-var": null,
"GET": {
"id": "22"
},
"REQUEST": [],

 I guess the documentation should say that not only `request_order` affects getVar()/$_REQUEST content
Reply
#6

Quote:request_order string

    This directive describes the order in which PHP registers GET, POST and Cookie variables into the _REQUEST array. Registration is done from left to right, newer values override older values.

    If this directive is not set, variables_order is used for $_REQUEST contents.

https://www.php.net/manual/en/ini.core.p...uest-order

Your $_REQUEST should have GET and POST values.
This is not CodeIgniter matter, but PHP matter.

It is very wired that your $_REQUEST is an empty array.
Reply
#7

(12-30-2022, 12:06 AM)kenjis Wrote:
Quote:request_order string

    This directive describes the order in which PHP registers GET, POST and Cookie variables into the _REQUEST array. Registration is done from left to right, newer values override older values.

    If this directive is not set, variables_order is used for $_REQUEST contents.

https://www.php.net/manual/en/ini.core.p...uest-order

Your $_REQUEST should have GET and POST values.
This is not CodeIgniter matter, but PHP matter.

It is very wired that your $_REQUEST is an empty array.

It is a default Ubuntu 20 / Nginx / PHP-FHM 8.1 setup
No customization
I agree that it is not a CI issue, but better to warn users that getVar/REQUEST depends not only on `request_order`
Reply
#8

Please try this:
https://stackoverflow.com/questions/2162...t-is-empty
Reply
#9

(12-30-2022, 01:40 AM)kenjis Wrote: Please try this:
https://stackoverflow.com/questions/2162...t-is-empty

No, i don't want my code to depend on any server environment
I will use getGet() for GET requests
Reply
#10

Okay, no problem.

I think it is better not to use getVar(), because if you use it, you don't know the value where comes from exactly.
It might cause security issues, although I do not believe the risk is high.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB