Welcome Guest, Not a member yet? Register   Sign In
Ajax hide controller from access.
#1

[eluser]Unknown[/eluser]
I have created a controller called ajax and within this have various functions to deal with ajax calls (index.php/ajax/getLogo) this is all working.

What would be the best way to stop access to this controller unless the request is coming from the ajax call?
#2

[eluser]eoinmcg[/eluser]
The way I usually handle ajax is to extend Controller with MY_Controller.php and add this method:\

Code:
function _is_ajax()
    {
        return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
    }

then in your ajax controller you can check like this
Code:
function ajax()
    {
        if(!$this->_is_ajax())
        {
            die('Not an Ajax request');
        }

        //rest of code goes here

    }
#3

[eluser]Unknown[/eluser]
Thanks for the pointer. Works perfectly :-)




Theme © iAndrew 2016 - Forum software by © MyBB