devadok Posted February 16, 2016 Share Posted February 16, 2016 Hi, I'm developing an addon and inside the hooks.php, I have the following code: if (!session_id()) { session_start(); } function my_addon_example() { $_SESSION['test_var'] = 'test_val'; } When a refresh the page and try to read the session var that I have set, the variable doesn't exist. Doesn't anybody knows what am I doing wrong? Thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted February 16, 2016 Share Posted February 16, 2016 you need to assign this function to ActionHook point first so WHMCS will call it each time this point triggered, like below: add_hook("ClientAreaPage", 1, "my_addon_example"); 0 Quote Link to comment Share on other sites More sharing options...
devadok Posted February 16, 2016 Author Share Posted February 16, 2016 Hi, sorry for didn't putting this on the code above, but this is being done: add_hook('AdminAreaHeaderOutput', 1, 'my_addon_example'); The function is being called in every refresh, as expetced. But I'm not able to read the $_SESSION values defined previously. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted February 16, 2016 Share Posted February 16, 2016 how or where do you need to read it? 0 Quote Link to comment Share on other sites More sharing options...
devadok Posted February 16, 2016 Author Share Posted February 16, 2016 Hi, basically I wanna do some "checking" code every x minutes. Example: Check if there is any new To-do Item. But instead of doing it on every refresh, I wanna check it every 10 minutes. add_hook('AdminAreaHeaderOutput', 1, 'check_something'); function check_something($vars) { $check = true; if (isset($_SESSION['last_checked'])) { $last_checked = $_SESSION['last_checked']; $now = time(); // cache 10 minutes - no need to check again if (($now - $last_checked) < (10 * 60)) { $check = false; } } if ($check) { // do some checking code // .... // update last checked time $_SESSION['last_checked'] = time(); } } Thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted February 16, 2016 Share Posted February 16, 2016 so the first function save some value and the second check this value, is this right? if this is the case change priority of second function add_hook('AdminAreaHeaderOutput', 2, 'check_something'); 0 Quote Link to comment Share on other sites More sharing options...
devadok Posted February 16, 2016 Author Share Posted February 16, 2016 Hi, in fact is the exact same function. It saves the value in a first page request and then tries to read it again in another page request. 0 Quote Link to comment Share on other sites More sharing options...
devadok Posted February 17, 2016 Author Share Posted February 17, 2016 Hi, it seems the problem was the following code: if (!session_id()) { session_start(); } After removing it, everything is working fine. Thanks. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.