php.htaccesscodeigniterfile-access

How to protect files in public folder in codeIgniter?


how can I protect files in the public folder in the CodeIgniter framework to be not viewed by a user who is not logged in? My public folder structure is as follows:

I am able to access the files using the below URLs without logging in to the system.

  1. https://<ip_address>/logs/detailed_logs
  2. https://<ip_address>/code/device.js

Can someone help me in making it only accessible to the user who is logged in?


Solution

  • I added the .htaccess file to the logs folder and allowed access only to the index.php file. I also created PHP files for each log file and checked whether a user is logged in using the session variable and read the contents of the respective log files when verified the user is logged in. Thanks for the help!