tags:

views:

154

answers:

2

Hello,

I have a huge controller in codeigniter, with many functions. I want to limit access to certain functions. How should I proceed?

And can I call the functions using cron daemon???

Or should I place those functions in another controller??

A: 

I have a huge controller in codeigniter, with many functions. I want to limit access to certain functions. How should I proceed?

You can use some access control based on session to limit access to certain controllers->functions only. At the start of the function you can place the code like if($_SESSION['user'] != 'xyz') exit('access denied') ;

And can I call the functions using cron daemon???

yes you can call any controller function in cron with this command wget https://www.example.com/controller-name/function-name

Or should I place those functions in another controller?? Its always a good idea to refactor the code if its getting very big and getting unmanageable.

shikhar
+2  A: 

Hi,

  1. a) To limit the access to functions in your controller you shold use private function declaration example:

function _example_function() {...} USING the underscore!!

This way its impossible to call this function by URL.

  1. b) Other simple way to restrict the access to functions in your controller is to use session variables and states to block the access.

2.) Yes you can use cron to run function just call the URL:

http://host/controller_name/FUNCTION

Regards,
Pedro

Pedro