PDA

View Full Version : One time hook per visit?


JamesAB
11-25-2008, 04:59 AM
Is there a hook that is called once when a user first logs in or when they return to the forum and they remain logged in because they have the "Remember Me" box ticked?

I'm looking at the login hooks, but I'm not sure what happens if the user has ticked the "Remember Me" box.

Would any of the login hooks still get called if they aren't typing in their username/password?

Basically all I need is a hook that is only called once per visit.

Thanks for your help,
James

ReCom
11-25-2008, 05:35 AM
I'm guessing that it must be one of those login_* hooks ...

JamesAB
12-02-2008, 10:34 PM
As far as I can tell, the login hooks are only called when the member actually enters their username & password to login, but not if they are a returning visitor who had the "Remember Me" box ticked.

Anyone have any ideas on this?

Thanks,
James

Guest190829
12-02-2008, 10:41 PM
You could use a global hook. Even though it is called on every page, you can use a conditional to only execute your code once per visit. You'll probably find a solution using cookies. :)

JamesAB
12-03-2008, 03:54 AM
You could use a global hook. Even though it is called on every page, you can use a conditional to only execute your code once per visit. You'll probably find a solution using cookies. :)
Thanks Danny.VBT.

I worked out a cookie solution with the global_start hook, comparing TIMENOW to the time I set in the cookie. If more than an hour has passed since the cookie was set, I run my code.

$recountcookie = COOKIE_PREFIX . 'recount';
$recountcookietime = TIMENOW;

$vbulletin->input->clean_gpc('c', $recountcookie, 'TYPE_INT');

if ($vbulletin->GPC["$recountcookie"] <= ($recountcookietime - 3600))
{
//Code to do my processing here
//and then set a new cookie
vbsetcookie('recount', $recountcookietime);
}

I also started looking at the article [How-To] Extend and use the Session Table Effectively (https://vborg.vbsupport.ru/showthread.php?t=152344)

Which method would use fewer resources on a busy forum, cookies or sessions?

Thanks,
James