CodeIgniter Forums
how to protect a controller function accessing by URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: how to protect a controller function accessing by URL (/thread-33236.html)



how to protect a controller function accessing by URL - El Forum - 08-19-2010

[eluser]Tracker[/eluser]
I don't want to access "deleteItems" function directly like this.
http://localhost/Shop/deleteItems/3

it should only accessible if i will call
http://localhost/Shop/deleteShop/3

Your help will be appreciated...

Code:
class Shop extends Controller {

    function deleteShop()
    {
        $this-> deleteItems($shopId);
        //….

    }

    function deleteItems($shopId)
    {
        //….

    }
}



how to protect a controller function accessing by URL - El Forum - 08-19-2010

[eluser]danmontgomery[/eluser]
This is covered in the user guide.

Quote:In some cases you may want certain functions hidden from public access. To make a function private, simply add an underscore as the name prefix and it will not be served via a URL request. For example, if you were to have a function like this:

Code:
function _utility()
{
  // some code
}
Trying to access it via the URL, like this, will not work:

Code:
example.com/index.php/blog/_utility/



how to protect a controller function accessing by URL - El Forum - 08-19-2010

[eluser]Tracker[/eluser]
Thank you very much.