I’m using codeigniter with jquery and it would be nice if you explain me how to protect the controller from direct access.
For example,
I have view with that standard jquery line:
$('#handler').load('tools/get_stats');
Tools it is my controller with function for loading statistics. If I write direct in browser full address of script http://site.com/tools/get_stats, browser open, of course, that data.
How to protect direct controller access from browser ? I want my data were loaded only in view, not on controller direct access.
The CodeIgniter Input Class has a method called
is_ajax_request()for this purpose.If you have a dedicated Ajax Controller, you can of course include this logic in the
__construct()method, otherwise it may be implemented on a method by method basis within your controllers.See: