Mohsin Inayat Khan
Mohsin Inayat Khan

Reputation: 1121

Prevent call to function from URL but allow internally

I have a controller which have a function test(). I want to make this function inaccessible when access by the URL and I can't make private or protected because I want the same function to used by other controllers.

How can I achieve this, any suggestions?

Upvotes: 0

Views: 175

Answers (1)

Matt
Matt

Reputation: 448

If the function file is brought in by include or require functions to the controller file then you could have something like this at the start of your function file:

defined("CONTROLLER") or die();

Then, before the include function calls the function file in, use:

define("CONTROLLER", true);

That way, the function file is killed by the die() command when accessed directly but runs as normal on any page you specifically included it in.

Upvotes: 1

Related Questions