Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL values with $_REQUEST in PHP

Tags:

php

request

If I am passing some parameters in the URL is it a bad practise to retrieve them using $_REQUEST super globa as opposed to $_GET super

like image 794
Aditya Shukla Avatar asked Feb 21 '26 07:02

Aditya Shukla


2 Answers

Well, since you expect them to be coming in as GET variables only, why use $_REQUEST and not $_GET?

The problem with $_REQUEST is that if there are variables of GET, POST and/or COOKIE, one will override the other in that superglobal. It's semi-predictable what values you end up getting if you try to access $_REQUEST.

like image 120
BoltClock Avatar answered Feb 23 '26 20:02

BoltClock


There are several issues with using $_REQUEST.

  1. It can be confusing to your future self and other maintainers as to where the data is coming from.
  2. It can cause collisions, and create hard-to-find bugs in which you are getting the wrong data (because $_REQUEST covers $_GET, $_POST, and $_COOKIE).

There may be others that I don't remember right now, too.

So yes, it's bad practice.

like image 23
Jonah Avatar answered Feb 23 '26 22:02

Jonah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!