![]() |
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-09-2009 [eluser]Arun Joshi[/eluser] I have a controller named 'posts' and a function 'ajaxLoadProperties' in it. This function will call via ajax to load some ajax contents. But if anyone trying to access this page directly by typing in address bar, this data will be available to users. Can I prevent direct access to this function/page ? That is keep this page only for ajax calling.. my path Code: http://localhost/mysite/posts/ajaxLoadProperties prevent direct access to this function/page ? - El Forum - 06-09-2009 [eluser]Dam1an[/eluser] you can add an underscore to the start of any function you don't want accessible directly via a URL, then you just need to make sure you use the underscore when calling it internally prevent direct access to this function/page ? - El Forum - 06-09-2009 [eluser]Arun Joshi[/eluser] Thanks Dam.... CI Rocks.......... prevent direct access to this function/page ? - El Forum - 06-09-2009 [eluser]cahva[/eluser] Hi, You can also prevent other than ajax request with: Code: if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])) For example when I have ajax functions in their own controllers so I put that to the constructor. prevent direct access to this function/page ? - El Forum - 06-10-2009 [eluser]Arun Joshi[/eluser] hi Damian, When I add underscore in function name it prevent me from accessing page via typing in address bar. Thats fine. But I cant access that page even through an ajax call. @cahva, I want to check the ajax call in a function in my controller. My controller is common for functions other than ajax calls. So I cant include this ajax path checking in my constructor. I need to check it in my function say ajaxRemove() in my controller say 'posts' prevent direct access to this function/page ? - El Forum - 06-10-2009 [eluser]Thorpe Obazee[/eluser] [quote author="Arun Joshi" date="1244643788"] @cahva, I want to check the ajax call in a function in my controller. My controller is common for functions other than ajax calls. So I cant include this ajax path checking in my constructor. I need to check it in my function say ajaxRemove() in my controller say 'posts'[/quote] Then check only in that method instead of putting it in the constructor. prevent direct access to this function/page ? - El Forum - 06-10-2009 [eluser]Arun Joshi[/eluser] Sorry bargainph, Its not working... I tried like this Code: function ajaxRemove() prevent direct access to this function/page ? - El Forum - 06-10-2009 [eluser]Thorpe Obazee[/eluser] Ajax helper: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Code: function ajaxremove() prevent direct access to this function/page ? - El Forum - 06-10-2009 [eluser]pistolPete[/eluser] I wouldn't rely on HTTP_X_REQUESTED_WITH. You could try using a POST request: Example JS code (using jQuery) Code: $.post("/your_controller/ajax_function", { ajax: "yes"}, PHP controller code: Code: function ajax_function() prevent direct access to this function/page ? - El Forum - 06-10-2009 [eluser]Arun Joshi[/eluser] I dont have ajax helper in my helpers folder. |