CodeIgniter Forums
prevent direct access to this function/page ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: prevent direct access to this function/page ? (/showthread.php?tid=19484)

Pages: 1 2


prevent direct access to this function/page ? - El Forum - 06-10-2009

[eluser]Arun Joshi[/eluser]
how can I download the ajax helper?


prevent direct access to this function/page ? - El Forum - 06-10-2009

[eluser]Dam1an[/eluser]
Just create a file called ajax_helper.php in the helpers directory and put the code bargainph gave earlier in it


prevent direct access to this function/page ? - El Forum - 06-10-2009

[eluser]Thorpe Obazee[/eluser]
Arun, you should not PM people for the same questions. It's what the forum is for.


prevent direct access to this function/page ? - El Forum - 07-09-2009

[eluser]bEz[/eluser]
An alternative method to the HELPER solution would be to create a new constant in:

./application/config/constant.php
Code:
/*
|--------------------------------------------------------------------------
| Define Ajax Request
|--------------------------------------------------------------------------
|
*/
define(
     'IS_AJAX',
     isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
     strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'
);

Line separated for clarity.

Stumbled upon this code while viewing the recent weblee screencast for JQuery (btw, a must view).

You can then change the controller code as follows:
Code:
if (! IS_AJAX)
{
  // not ajax
} else {
  // ajax
}

Subtle change, but it works!