I have built a site with codeigniter 3.
I want to prevent run all php files directly. imagine that I have a file named test.php in my root.
When the user goes to a site.com/test.php , it is not possible to access it. Not for a specific file but for all PHP files.
I want to access the site only by calling the controls and their methods like : site.com/user/login
2
Answers
You have to add this code in your .htaccess
The sure-fire way – which is also the approach most modern php frameworks use – is to actually have a document root that does not contain php files you don’t want exposed.
This can also be done in codeigniter with a little trick:
public/
directory in your project. This will be the document root, everything in there will be public.index.php
file there with just "hello world" for testing/var/www/html
, in your case, it should now be/var/www/html/public
.