LightScribe Posted December 6, 2017 Share Posted December 6, 2017 How to include init.php in my other class functions? Here is my code example. <?php DEFINE('ROOT_PATH', $_SERVER['DOCUMENT_ROOT']); require_once ROOT_PATH.'/forums/init.php'; class getForum { public function isLoggedIn() { $member = \IPS\Session\Front::i()->member; if ($member->member_group_id != \IPS\Settings::i()->guest_group) { return true; } else { return false; } return false; } } The problem now is that I cant access to init.php classes... Quote Fatal error: Class 'IPS\Session\Front' not found in .... Link to comment Share on other sites More sharing options...
0 Cookie Monster Posted December 6, 2017 Share Posted December 6, 2017 3 hours ago, LightScribe said: Ok, if you suggest me using this api then please explain me how can I make for example users online script in efficient way. I have 30k registered users and I want show users who have been active in the last 30 minutes, I can sort by lastactivity but I can't set in parameters ( i think) these 30 minutes. Thats mean to do that I need on every page load, loop all 30k users and check lastActivity object for each member. That I think is not efficient. So far, I have not found in this API where i can check if a user is logged in or not. E: Btw i fixed my problem, i removed my define from top because that was defined in init.php, very stupid mistake but ty all for help Like I said, to check if a user is logged in or not you check if they are authorized. In the API you have to be authorized to make POST / GET request to certain endpoints. If they do NOT have a token (which they get by logging in) then they are not logged in. When it comes to the question regarding the lastActivity. You can loop over all members, and show the one with the latest timestamp. This gets pushed into an array and then be displayed ordered by or counted. I'm more of an Angular person and JS so I don't know for PHP but the thing would be the same. anyways glad you fixed the issue. 1 Liked what i posted remember to feed me a cookie ->Or you can add a cookie to my Link to comment Share on other sites More sharing options...
0 Cookie Monster Posted December 6, 2017 Share Posted December 6, 2017 What are you trying to achieve ? the init.php is normally there to start the whole process not just do the login btw. Liked what i posted remember to feed me a cookie ->Or you can add a cookie to my Link to comment Share on other sites More sharing options...
0 LightScribe Posted December 6, 2017 Author Share Posted December 6, 2017 6 minutes ago, Cookie Monster said: What are you trying to achieve ? the init.php is normally there to start the whole process not just do the login btw. Im trying to make my own functions to more easily code my page. For example I dont want every time write this to check member is logged in or not $member = \IPS\Session\Front::i()->member; if ($member->member_group_id != \IPS\Settings::i()->guest_group) I want just do this $forum = new getForum(); if ($forum->isLoggedIn() == true) I hope you understand my idea... Link to comment Share on other sites More sharing options...
0 Cookie Monster Posted December 6, 2017 Share Posted December 6, 2017 Would it not be easier instead of just grab random functions that depends on other files to use the REST API ? Thats just what it is for, The REST API, make a authorization call to the endpoint store the token. Then check if the user has the token. If they have the token they are logged in. If they don't then we know they are not authenticated so we treat them as a guest. https://invisioncommunity.com/developers/rest-api Liked what i posted remember to feed me a cookie ->Or you can add a cookie to my Link to comment Share on other sites More sharing options...
0 LightScribe Posted December 6, 2017 Author Share Posted December 6, 2017 14 minutes ago, Cookie Monster said: Would it not be easier instead of just grab random functions that depends on other files to use the REST API ? Thats just what it is for, The REST API, make a authorization call to the endpoint store the token. Then check if the user has the token. If they have the token they are logged in. If they don't then we know they are not authenticated so we treat them as a guest. https://invisioncommunity.com/developers/rest-api Random functions? Wtf bro REST API have very limited functions and usage and why I need use API on the same host if I could just get classes... Link to comment Share on other sites More sharing options...
0 Cookie Monster Posted December 6, 2017 Share Posted December 6, 2017 1 hour ago, LightScribe said: Random functions? Wtf bro REST API have very limited functions and usage and why I need use API on the same host if I could just get classes... Alright, let me ask this and i will have to edit my posts accordingly. Are you creating your own website / page (in PHP) that is been connected to the forum. OR Are you creating a page /application / plugin inside the forum (using IPS Pages) etc. Liked what i posted remember to feed me a cookie ->Or you can add a cookie to my Link to comment Share on other sites More sharing options...
0 LightScribe Posted December 6, 2017 Author Share Posted December 6, 2017 1 minute ago, Cookie Monster said: Alright, let me ask this and i will have to edit my posts accordingly. Are you creating your own website / page (in PHP) that is been connected to the forum. OR Are you creating a page /application / plugin inside the forum (using IPS Pages) etc. Im creating my own page which is connected to the forum Link to comment Share on other sites More sharing options...
0 Cookie Monster Posted December 6, 2017 Share Posted December 6, 2017 1 hour ago, LightScribe said: Im creating my own page which is connected to the forum So then instead of modifying and pull(ing) out classes and functions from a place, the REST API is used to do exactly that. You can, of course, do it but I would not recommend it. The REST API was created to make things like that work in a good and easy fashion (So an outside website or Application) can talk to the forum. When you say limited (What is it that you mean with it) What functionality are you missing? As with the API, you can do the following. Full CRUD functionality (Create, Read (View), Update, Delete) for (Forum, Calendar, Downloads, Blog, Gallery, E-Commerce) Check if a user is logged in or not. Create, Update, View, Delete Users from your application So I'm not sure what you are referring to as limited / lacking. Liked what i posted remember to feed me a cookie ->Or you can add a cookie to my Link to comment Share on other sites More sharing options...
0 LightScribe Posted December 6, 2017 Author Share Posted December 6, 2017 (edited) 2 hours ago, Cookie Monster said: So then instead of modifying and pull(ing) out classes and functions from a place, the REST API is used to do exactly that. You can, of course, do it but I would not recommend it. The REST API was created to make things like that work in a good and easy fashion (So an outside website or Application) can talk to the forum. When you say limited (What is it that you mean with it) What functionality are you missing? As with the API, you can do the following. Full CRUD functionality (Create, Read (View), Update, Delete) for (Forum, Calendar, Downloads, Blog, Gallery, E-Commerce) Check if a user is logged in or not. Create, Update, View, Delete Users from your application So I'm not sure what you are referring to as limited / lacking. Ok, if you suggest me using this api then please explain me how can I make for example users online script in efficient way. I have 30k registered users and I want show users who have been active in the last 30 minutes, I can sort by lastactivity but I can't set in parameters ( i think) these 30 minutes. Thats mean to do that I need on every page load, loop all 30k users and check lastActivity object for each member. That I think is not efficient. So far, I have not found in this API where i can check if a user is logged in or not. E: Btw i fixed my problem, i removed my define from top because that was defined in init.php, very stupid mistake but ty all for help Edited December 6, 2017 by LightScribe Link to comment Share on other sites More sharing options...
0 Ali Veli Posted December 8, 2017 Share Posted December 8, 2017 API is sometimes not enough. So I'm using it in a hybrid way. init.php and IPB functions classes and API when its easy peasy. Link to comment Share on other sites More sharing options...
0 Cookie Monster Posted December 8, 2017 Share Posted December 8, 2017 6 hours ago, Ali Veli said: API is sometimes not enough. So I'm using it in a hybrid way. init.php and IPB functions classes and API when its easy peasy. As i said before i work mostly from the frontend with Typescript so i don't do the inti.php part i don't need it i got an API for 90% of what i need. Liked what i posted remember to feed me a cookie ->Or you can add a cookie to my Link to comment Share on other sites More sharing options...
0 Administrator Tony Posted December 17, 2017 Administrator Share Posted December 17, 2017 The question(s) in this support topic have been answered and the topic author has resolved their issue. This topic is now closed. If you have other questions, please open a new topic. Link to comment Share on other sites More sharing options...
Question
LightScribe
How to include init.php in my other class functions? Here is my code example.
The problem now is that I cant access to init.php classes...
Link to comment
Share on other sites
12 answers to this question
Recommended Posts