I want to know if there is any way through which I can restrict access to my controller functions through URL. But I want to give them a call through my link in the site. For example if I have a link in my site which points to a controller function:
<a href='test/function'>Call me</a>
But I don't want the controller function to be called when I place the above URL in my browser address bar. Can anyone help with this?
As you stated in the comment, that if you want to load the link via AJAX:
Your markup:
Your jquery:
Then in you CodeIgniter controller, you check to see if your key is present and matches ("abc"), else you return a 403 or something simillar.
Also, you could of course check the
$_SERVER['HTTP_REFERER']
to see where the user came from (this is however quite easily spoofed) and only allow access when the GET-request is made from your own site.Solution: put this code at the beginning of every controller method
This really helped. I also added this as an added check
This is not possible. Apache and, consequently CodeIgniter, is allowing access to your PHP script to the outside world whether through a manually entered browser URL or through a visited hyperlink. Both scenarios connect to your web application in the exact same way, but they just get there differently.
You can allow access to only your CodeIgniter scripts (i.e. prevent public users from accessing a controller) by using:
As Marcus has pointed out, you could use something like:
But it's often very inconsistent.
form validation you will put inside this if condition..This will definitely work..