Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict people by using PHP GET Variable

Tags:

php

get

In one of the interview question i get below question

"How you can restrict your developers in your custom build framework to use $_GET variable."

We have our own custom build framework but in our framework we can not restrict people to use $_GET or $_POST in place of $this->request->get or $this->request->post.

We have method for accessing this variable but people most of the time uses $_GET or $_POST instead of our methods.

Can you please give me answer for that?

Thanks

like image 937
user1817490 Avatar asked Nov 12 '12 07:11

user1817490


1 Answers

In php.ini, remove the G and P characters from the variables_order option.

Alternatively, if you want them to hate you forever, you could copy the contents of the superglobal, then set it to an instance of a class that throws an exception whenever you try to interact with it:

class supaglobal implements arrayaccess
{
    public function _construct(){}

    function offsetExists($offset) {
        throw new Exception("Don't use GET, bro");
    }
    function offsetSet($property, $value){
        throw new Exception("Don't use GET, bro");
    }
    function offsetUnset($property) {
        throw new Exception("Don't use GET, bro");
    }
    function offsetGet($property){
        throw new Exception("Don't use GET, bro");
    }
}

$approvedget = $_GET;
$_GET = new supaglobal();
$abcd = $_GET["abcd"]; // throws exception
$abcd = $approvedget["abcd"]; // A - OK
like image 96
Asad Saeeduddin Avatar answered Sep 29 '22 06:09

Asad Saeeduddin