Admin Login Hook (Fetch Update When Admin Logs In)

Hi all!

Is there a way to execute my function each time administrator logs in to admin panel? I looked for admin/login hooks, but failed to find any. Please, help me out if I am missing something.

Example when it might be useful. My add-on uses data from 3rd party website. Data-provider is logistic company, that has a really large XML file on their server, what is updated periodically. My goal is to keep delivery prices in my add-on up to date, that is why I need to download and parse this file to find changes.

I know I can use cron to to this, but it becomes quite complicated for administrators to setup my addon if they need to configure cronjob separately. Hosting providers have different (mostly ugly and complicated) UIs for cronjob configuration, some feature limitations for number of active cronjobs and some VPS providers offer only command-line access to cronjob.

That is why I want to have everything built into my addon, and provide administrator with straight-forward way of installing it. Every time admin logs into CS-Cart admin panel, hook activates, checks if remote file was changed, downloads it and processes. As (mostly) admins are logging into admin area almost on a daily basis, it will help to get rid of cron.

Thank you for any ideas!


I think, better to create separate controller for your function and add menu item for this controller.

Each time, just open this script in the next tab. Also you do not have to wait to run the script at login.

Regarding your question: app/functions/fn.users.php → function fn_login_user → login_user_pre hook

Thank you.

Use the 'fill_auth' php hook.

Set a cookie with a timestamp in it.

If cookie not set or timestamp older than what you desire execute the function and reset the cookile. I.e. similar to:

fn_my_changes_fill_auth(&$auth, &$user_data, $area) {
$some_seconds = SECONDS_IN_DAY;
if( $area == 'A' && (empty($_COOKIES['my_cookie_name']) || $_COOKIES['my_cookie_name'] < (TIME - $some_seconds) ) ) {
fn_set_cookie('my_cookie_name', TIME);