Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

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
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

I'm currently in the (imposed) process of migrating my site from phpBB 3.0.14 to 3.2.1, and having got the basic forum working in isolation (www.portorleans.org/forumtest/) I now need to start tackling the various bits of code that I'm currently using to display posts and other information on my site's home page (www.portorleans.org) and other locations. The code is based on, or perhaps more accurately cobbled together from, the instructions given here: https://wiki.phpbb.com/Practical.Displa ... rnal_pages .

So far though, even the basic setup header code does not seem to work in 3.2.1. Or rather it does, but even a fairly simple PHP command later in the page fails. Here's a really simplified test page which doesn't even try to do anything with the content yet, it just sets up the system:

Code: Select all

<?php
	define('IN_PHPBB', true);
	$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
	$phpEx = substr(strrchr(__FILE__, '.'), 1);
	require_once($phpbb_root_path . 'common.' . $phpEx);
	require_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
	require_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
	require_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
	// Start session management
	$user->session_begin();
	$auth->acl($user->data);
	$user->setup('viewforum'); 
?>
<!DOCTYPE html>
<html>
<head>
<title>phpBB Test Page</title>
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
</head>

<body>

<h1>Test with phpBB 3.0.14 forum (using folder /forum/)</h1>

<p> 
<?php
echo 'Test of PHP echo command. ' ;
echo 'Filedate = ' . date("Y-m-d",filemtime(substr($_SERVER['PHP_SELF'],1))) ;
?>
</p>

</body>
</html>
When I point the folder name to my 3.0.14 production system (using ./forum/ as shown above) the simple test page behaves as expected. See results at http://www.portorleans.org/test_3.0.php

However when I point that first line to the new 3.2.1 system (./forumtest) I get an error as soon as any subsequent PHP code tries to do anything useful. See results at http://www.portorleans.org/test_3.2.php

Any thoughts as to what I need to change for use with 3.2.1? If I can't get even that basic test snippet working there's not much point looking at the more complex stuff yet...

Andre
--- Admin of www.portorleans.org
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by david63 »

The error message is telling you what the problem is - the use of $_SERVER
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
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

Thanks David. I did read the error message, but I don't understand why phpBB 3.2.1 setup is somehow breaking fundamental PHP variable access, when 3.0.14 is fine.

Surely that one line of code shouldn't cause any PHP errors, and even just trying to echo the simplest $_SERVER['PHP_SELF'] filename fails after the 3.2.1 setup code has been run.

Andre
Last edited by andrewilley on Sun Sep 10, 2017 10:05 am, edited 1 time in total.
--- Admin of www.portorleans.org
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by david63 »

It is the way that phpBB have gone with globals I'm afraid - you can turn then on in phpBB (not sure how off the top of my head!!)
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
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

Ugh, how the heck am I going to work on goodness-knows how many lines of valid code if phpBB is breaking even minor regular PHP variables ... Why would they do that?!

Andre
--- Admin of www.portorleans.org
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by canonknipser »

andrewilley wrote: Sun Sep 10, 2017 10:09 am Why would they do that?!
Short answer: Security, especially in extension development:
You should use the request-class instead of direct calling superglobals, because the variable from the request class are already sanitized.
See discussion here: http://area51.phpbb.com/phpBB/viewtopic ... perglobals
and the api doc for the request class: https://area51.phpbb.com/docs/code/3.1. ... hod_server

Edit: You'll also find some hints in the coding guidelines: http://area51.phpbb.com/docs/32x/coding ... ml#general
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

I've just checked, and I have well over 200 super global accesses on my site, so recoding all of them would be a major task. I've tried using $request->enable_super_globals(); to test, and that works for this test at least.

I think I'm just going to have to go down the global route (although I can't find the mentioned global parameter file /phpbb/config/parameters.yml in 3.2.1, so it looks like it's been moved :( ).

Andre
--- Admin of www.portorleans.org
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

I'm actually making a LOT of progress now. Finding out what was causing the PHP superglobals problem was the biggie, thank you.

I've now added $request->enable_super_globals() as part of my page header code immediately after the forum initialisation is complete, and most stuff is now working reasonably well with remarkably little code modification.

I found I needed to change a couple of references to t.topic_approved to t.topic_visibility, and I also had to remove one SQL query term t.topic_replies_real, which presumably has been taken out of the database since 3.0.14? I wasn't using it anyway, but it was present in one general search function.

With those changes applied on my test server, most of my pages are now loading OK, although some formatting is a little off. But at least now I'm in the more familiar territory of routine debugging rather than "hell, nothing will load at all".

Over time I'll dig out all the superglobal references and replace them with more secure requests instead, but that will have to wait as I've currently got a tight deadline to get this all of this working with phpBB 3.2.1 as my server provider intends to turn off PHP 5.6 support in a couple of weeks.

Andre
--- Admin of www.portorleans.org
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

I still haven't managed to find the permanent parameter setting to allow the use of PHP superglobal variables with 3.2.1, does anyone know where it was moved to?

Andre
--- Admin of www.portorleans.org
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by david63 »

You could try playing around with the disable_super_globals() and enable_super_globals() functions in phpbb/request/request.php but I have no idea what the possible consequences could be on the core phpBB code
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
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

I'm using the enable_super_globals() function already in a couple of pages via my header code, but that's going to be a pain to pepper around goodness knows how many bits of code that will be jumped in and out of when I fully integrate the new forum into my site layout (as per my live site, www.portorleans.org/forum). I just want to get rid of it completely ideally.

[Edit] Ah, I see what you mean, you meant to edit those actual functions themselves to disable their actions. Yes, I had thought of that as an option, but it'd be nicer to use a clean parameter setting in order to avoid possible complications.

Andre
--- Admin of www.portorleans.org
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by david63 »

Another suggestion, but again no idea of the consequences, add enable_super_globals() at the end of common.php
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
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

I gave up trying on the global solution and ended up wrapping enable() and disable() functions around my main code blocks. It took most of a day's work to find and test everything, but at least it's done now.

Luckily out of the 175+ "$_xxx" references on my pages, a large number were from one common header line in every page which I found I could actually batch remove, and the rest were contained in about six pages so were not too hard to isolate and wrap.

Anyway, hopefully that work will now make re-integrating my forum's CSS and drop-down menu include code back into the prosilver overall_header.html page a bit easier. Even if that takes a while, the main site will function perfectly well with that page still using its own stand-alone formatting (if I hit the crunch PHP 5.6 cutoff deadline before that's finished).

Thanks everyone for the help, I would still have been at square one without you.

Andre
--- Admin of www.portorleans.org
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

Darn, so close now, but one last question...

I'm almost done with integrating the new phpBB 3.2.1 forum into my overall site layout by adding various includes to my own header, menu, etc modules into styles/prosilver/template/overall_header.html. Apart from a few minor CSS tweaks for header positioning it's pretty much done now (see www.portorleans.org/forumtest/, on a desktop not a mobile for now).

This is how my common headers code is inserted within overall_header.html:

Code: Select all

<!DOCTYPE html>
<html dir="{S_CONTENT_DIRECTION}" lang="{S_USER_LANG}">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- INCLUDEPHP ../include-commonheaders.php -->
{META}

...... etc ........
This all works fine and all my own code runs correctly until I enable the specific enable_super_globals() module within include_commonheaders.php. As soon as I do, I get the following error message which seems to be saying that the required function is not available.

Code: Select all

Fatal error: Uncaught Error: Call to a member function enable_super_globals() on null in /volume1/web/include-commonheaders.php:2 Stack trace: #0 /volume1/web/forum/cache/production/twig/8d/8d6d5c32e5d295eadef9c8ba9a4c43252c368280adfe77384d7a263592dc9cac.php(45): require() #1 /volume1/web/forum/vendor/twig/twig/lib/Twig/Template.php(432): __TwigTemplate_04cd78051ccb10e615416e9e1f959befc6a7874b186b259ceadab68efb97d79d->doDisplay(Array, Array) #2 /volume1/web/forum/vendor/twig/twig/lib/Twig/Template.php(403): Twig_Template->displayWithErrorHandling(Array, Array) #3 /volume1/web/forum/cache/production/twig/60/601a9b825c55f4bfe3b7953acd99f3c580f1f1a845398be92bfe6fd3443c6a61.php(26): Twig_Template->display(Array) #4 /volume1/web/forum/vendor/twig/twig/lib/Twig/Template.php(432): __TwigTemplate_1c1c930ab477627976c4f9941621064bb6307a5c5e1cb9fe806919281003eab8->doDisplay(Array, Array) #5 /volume1/web/forum/vendor/twig/twig/lib/Twig/Template.php(403): Twig_Template->displayWithErrorHandling(Array, Array) #6 /volume1/web/forum/vend in /volume1/web/include-commonheaders.php on line 2
The same included php file works fine (with the enable_super_globals() feature activated) from my homepage, newspage, etc. so it must be related to where within the phpBB setup process the call is being defined.

I think this is now the last bit I need to fix. So close....!

Andre
--- Admin of www.portorleans.org
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Displaying posts from phpBB 3.2.1 on site homepage, can't even get setup to work

Post by andrewilley »

[edited out my stupidity]

Adding global $request; was all that was needed, it wasn't actually the function call at all. Solved.

Andre
--- Admin of www.portorleans.org

Return to “phpBB Custom Coding”