Integration of phpBB API into existing page

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
dbj
Registered User
Posts: 74
Joined: Mon Oct 09, 2017 10:08 am

Integration of phpBB API into existing page

Post by dbj »

Hi,

we would like to use the phpBB API for an existing page instead of modifying the tables directly (which, after some years of operation, has lead to some database corruption...)

But: Including the necessary phpBB files to be able to call functions like add_user breaks the existing page because phpBB makes severe changes to the runtime environment (superglobals, error reporting etc.)

So we are currently stuck with two options:

1.) Always call the phpBB functions last, i.e. at the end of the script of the existing page. But this is very unflexible and makes error-handling impossible.

2.) Rebuild the functions like add_user and user_update_name to work without including all the "phpBB stuff". But this seems like a very complex tasks because those functions depend on other functions which then would also be required to be rebuilt/copied...

Is there any other way? Is it somehow possible to "encapsulate" the call to the phpBB API? (No, using exec() or other system calls to another script which handles this is not an option because using exec() is not an option.)
User avatar
AmigoJack
Registered User
Posts: 6113
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Integration of phpBB API into existing page

Post by AmigoJack »

dbj wrote: Mon Oct 09, 2017 10:54 amIncluding the necessary phpBB files to be able to call functions like add_user breaks the existing page because phpBB makes severe changes to the runtime environment (superglobals, error reporting etc.)
In theory all those changes can be undone. Practically you surely mean user_add() and based on how many functions you use off phpBB you can write your own file as slimmed substitution for files like /common.php and /includes/startup.php. Either way you have to go thru the code and just see what's changed to later change it back.
dbj wrote: Mon Oct 09, 2017 10:54 amIs there any other way?
You could write your own PHP file which is then called simply thru something like

Code: Select all

$output= file_get_contents( 'http://www.example.com/myfile.php?mode=add&user=name&pass=123' );
which comes along with questions about securing access to that file.
dbj wrote: Mon Oct 09, 2017 10:54 amusing exec() ... is not an option because using exec() is not an option
Glad we sorted that.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
dbj
Registered User
Posts: 74
Joined: Mon Oct 09, 2017 10:08 am

Re: Integration of phpBB API into existing page

Post by dbj »

AmigoJack wrote: Mon Oct 09, 2017 11:22 am you can write your own file as slimmed substitution for files like /common.php and /includes/startup.php.
Wouldn't this have a very high probability of breaking with an update of phpBB?
So I would have to scan through these files after every update to see if I need to make changes to my files.
Same argument of course goes for imitating what user_add() is doing - if an update changes how these functions are working, I must change my "copy" of it.
AmigoJack wrote: Mon Oct 09, 2017 11:22 amwhich comes along with questions about securing access to that file.
That would be a big drawback of this solution and rule it out. (Of course it should not be hard writing a .htaccess file only allowing requests from localhost for this file - but I think everyone agrees this is a very hacky solution.)
AmigoJack wrote: Mon Oct 09, 2017 11:22 am
dbj wrote: Mon Oct 09, 2017 10:54 amusing exec() ... is not an option because using exec() is not an option
Glad we sorted that.
Of course I meant because exec() and similar functions are not available at all, they are also not available for this particular task ;)

So the question is, what is the best way to interact with phpBB from another application
  • That does not break with an update unless the API itself changes (e.g. phpbb_hash() removed in upcoming version)
  • That does not impose further security considerations (e.g. restricting access to particular files)
  • That does not break an existing application (by modifying the runtime environment)
I guess such a way does not exist? :)
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Integration of phpBB API into existing page

Post by david63 »

I think that the point is that phpBB does not, at the moment, have an "API" in the true sense otherwise you would be able call any function you wanted without any need to modify code.

Depending on what it is that you are trying to do it might be a possibility to create your requirements as an extension where you will have access to all of phpBB's functionality without the problem of having to deal with update.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
dbj
Registered User
Posts: 74
Joined: Mon Oct 09, 2017 10:08 am

Re: Integration of phpBB API into existing page

Post by dbj »

We need to do three things:
  • Add users to phpBB
  • Change user details like nickname, password, e-mail
  • Remove/delete users
Generally speaking, we need "full access" to the phpBB user database.

How would an extension handle this?
I would need to somehow include this extension in my other application, right?
But then again this extension would likely load all the phpBB stuff?
I'm not familiar with developing extensions for phpBB, so I might be off here.
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26546
Joined: Fri Aug 29, 2008 9:49 am

Re: Integration of phpBB API into existing page

Post by Mick »

I’ve moved this to the custom coding forum where you are quite at liberty to discuss your coding requirements. In the meantime I suggest you make an extension request, it costs nothing and someone may take up the challenge.
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Integration of phpBB API into existing page

Post by david63 »

dbj wrote: Mon Oct 09, 2017 12:17 pm Add users to phpBB
There is already an extension that will do that
dbj wrote: Mon Oct 09, 2017 12:17 pm Change user details like nickname, password, e-mail
Remove/delete users
Both of those are core features of phpBB

... or am I misunderstanding you?
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
dbj
Registered User
Posts: 74
Joined: Mon Oct 09, 2017 10:08 am

Re: Integration of phpBB API into existing page

Post by dbj »

david63 wrote: Mon Oct 09, 2017 1:02 pm... or am I misunderstanding you?
Probably. We have a website with two applications, our own code and phpBB. Registrations in phpBB are disabled, users may only register through the main website, which then adds the users to the phpBB database. Until now, we did this by executing SQL statements on the phpBB tables directly. That has lead so some database corruption as we were doing this naively without considering side effects. (Updating the last registered username and so on...)

So we looked at the following: https://wiki.phpbb.com/Add_users

But in order for this to work, we need to load phpBB-specific includes/code in our own non-phpBB software:

Code: Select all

        define('FORUM_ADD', true);
        define('IN_PHPBB', true);
        define('IN_PORTAL', true);
        define('PHPBB_ROOT_PATH', './scripte/forum/');
        define('USERS_TABLE', "phpbb_users");
        $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
        $phpEx = substr(strrchr(__FILE__, '.'), 1);
        include($phpbb_root_path . 'common.' . $phpEx);
        include($phpbb_root_path . '/includes/functions_user.' . $phpEx);
But this breaks our application, for example because superglobals are disabled. Thus the questions asked in this post come to mind.
User avatar
AmigoJack
Registered User
Posts: 6113
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Integration of phpBB API into existing page

Post by AmigoJack »

dbj wrote: Mon Oct 09, 2017 11:48 amI think everyone agrees this is a very hacky solution
No - the script just has to authorize access, which can be as simple as "is a specific parameter given and does its value equal to a given pass phrase". There you have your API and both input and output can be done completely to your will - you just have to call it thru HTTP.
Last edited by AmigoJack on Tue Oct 10, 2017 7:11 am, edited 1 time in total.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
dbj
Registered User
Posts: 74
Joined: Mon Oct 09, 2017 10:08 am

Re: Integration of phpBB API into existing page

Post by dbj »

This could probably indeed be realized as an extension implementing some kind of REST API.

I've seen there is already some kind of activity... http://area51.phpbb.com/phpBB/viewtopic ... 08&t=42731

But it looks like this will never go live, so waiting for it will most likely not be fruitful.
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26546
Joined: Fri Aug 29, 2008 9:49 am

Re: Integration of phpBB API into existing page

Post by Mick »

dbj wrote: Mon Oct 09, 2017 2:34 pmwaiting for it will most likely not be fruitful.
Mick wrote: Mon Oct 09, 2017 1:01 pmIn the meantime I suggest you make an extension request, it costs nothing and someone may take up the challenge
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel
User avatar
dbj
Registered User
Posts: 74
Joined: Mon Oct 09, 2017 10:08 am

Re: Integration of phpBB API into existing page

Post by dbj »

Thanks for your support. For now we found that these two lines are sufficient to make our page working again after interacting with phpBB.

Code: Select all

$request->enable_super_globals();
set_error_handler(NULL);
Post Reply

Return to “phpBB Custom Coding”