Search code examples
phpcodeignitercachingion-auth

Run a cron and visit codeigniter controller which is secured by ion_auth module


I'm building a codeignite project in which i use the Ion_Auth module written by Ben Edmund to secure a certain range of web pages. I do want to make it possible to let a cron job visit this range of pages that are secured by the Ion_Auth module, using a php script or a codeigniter controller. The goal of visiting these pages is being able to cache and store this range of pages every midnight so the files in the cache folder will be deleted and new cache files are written by paying a visit to each of the pages that need to be cached.

Configuring the cronjob is the easy part, but using a php file to login and giving it access and let it visit these secured pages that need to be cached, that is where i get stuck. Any advice, tips, strategy's are welcome since i believe this is kind of a tricky thing to do...

My guess is to start with a php file that can only be accessed by a cron job. So intruders won't be able to access it. But i have no clue, how to make it login so it can visit the pages that i need to being visited? And i'm not sure if this is a secure approach.


Solution

  • Look at PHP Curl, you may need to enable cookies if the authentication module uses sessions. In general you need to create a request to GET each page you want re-cached. You will have to recreate the HTTP sequence that a browser would, which means you will have to maintain state between curl_exec calls, unless the authentication module is RESTful, but I doubt this is the case since you didn't mention it.