Jump to content
  • 0
LightScribe

Include init.php

Question

LightScribe    0

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 ....

 

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0
Cookie Monster    656

What are you trying to achieve ?

the init.php is normally there to start the whole process not just do the login btw.

Share this post


Link to post
Share on other sites
  • 0
LightScribe    0
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...

Share this post


Link to post
Share on other sites
  • 0
Cookie Monster    656

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

 

Share this post


Link to post
Share on other sites
  • 0
LightScribe    0
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 :D

REST API have very limited functions and usage and why I need use API on the same host if I could just get classes...

Share this post


Link to post
Share on other sites
  • 0
Cookie Monster    656
1 hour ago, LightScribe said:

Random functions? Wtf bro :D

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.

Share this post


Link to post
Share on other sites
  • 0
LightScribe    0
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

Share this post


Link to post
Share on other sites
  • 0
Cookie Monster    656
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.

 

Share this post


Link to post
Share on other sites
  • 0
LightScribe    0
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 :D

Edited by LightScribe

Share this post


Link to post
Share on other sites
  • 0
Cookie Monster    656
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 :D

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.

  • Thanks 1

Share this post


Link to post
Share on other sites
  • 0
Ali Veli    1

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. 

Share this post


Link to post
Share on other sites
  • 0
Cookie Monster    656
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.

Share this post


Link to post
Share on other sites
What do you think? Remember the human.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

×