LiveEn
LiveEn

Reputation: 3253

access function only though link using codeigniter

im having a small system where there is an link to activate or deacctivate the users..

so i have my function which lists down the users

function users()
{
//the code
}

and there is a function that takes the 3rd uri segment which is the id and sets the user as activated or deactivate.

function action_settings()
{
// the code
}

i want to make sure that the action_settings is accessed only through the function users and not allow any users to directly access that function.

so the link

localhost/motivators/action_settings/25

must be accessible only through the link from

localhost/motivators/users/

is it possible implement this restriction in Codeigniter?

Upvotes: 0

Views: 147

Answers (2)

mallix
mallix

Reputation: 1429

Try inside function action_settings():

function action_settings(){

 if($_SERVER['HTTP_REFERER'] != 'http://localhost/motivators/users'){
  //wrong referer
  exit();
 }

 //activate user
}

It could also be:

function action_settings(){

 if($_SERVER['HTTP_REFERER'] != base_url() . 'motivators/users'){
  //wrong referer
  exit();
 }

 //activate user
}

Upvotes: 1

mamdouh alramadan
mamdouh alramadan

Reputation: 8528

what you can do is that to supply the uri->uri_string as an argument to your action_string function (method) and parse it to check if it contains motivators/users/ or just users then continue with action_string process. otherwise, don't.

Upvotes: 1

Related Questions