How to use PHP in phpBB3. All files seem .html

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Suggested Hosts
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
zentropy
Registered User
Posts: 85
Joined: Thu Nov 01, 2007 12:27 am

How to use PHP in phpBB3. All files seem .html

Post by zentropy » Tue Nov 06, 2007 4:14 pm

I wanted to add extra graphical elements to a phpBB3 forum, which are dynamically built by a php script.
The php script can't be added to any of the .html files like overall_header.html or index_body.html , because simply they're all .html files. PHP code is by default not parsed in .html files only if some settings are changed which say that .html files should also be scanned for php code and parsed. I'm trying to avoid this, so i'm wondering how to use PHP in the .html files of phpBB3.

rxu
Extensions Development Team
Posts: 3003
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: How to use PHP in phpBB3. All files seem .html

Post by rxu » Tue Nov 06, 2007 4:40 pm

Saying shortly, you can put your PHP code into appropriate php file and use phpBB3 template engine to build html code.

zentropy
Registered User
Posts: 85
Joined: Thu Nov 01, 2007 12:27 am

Re: How to use PHP in phpBB3. All files seem .html

Post by zentropy » Tue Nov 06, 2007 5:17 pm

Is that the way it is generally done? If so where can i find any tutorial/documentation on how to exactly use this template engine to parse .php files and then include the parsed code into the template .html files?

rxu
Extensions Development Team
Posts: 3003
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: How to use PHP in phpBB3. All files seem .html

Post by rxu » Tue Nov 06, 2007 5:24 pm

Some phpBB3 source code documentationd is here.

zentropy
Registered User
Posts: 85
Joined: Thu Nov 01, 2007 12:27 am

Re: How to use PHP in phpBB3. All files seem .html

Post by zentropy » Tue Nov 06, 2007 6:08 pm

What i'm trying to accomplish is add the parsed output(some dynamically determined images) of a php script to overall_head.html , but because overall_head.html is an html file i can't add the php script. It's a rather small php script nothing fancy. Are you sure the phpBB3 source code is needed to accomplish it?

What i tried before was add the php script to overall_head.html and then rename the file to overall_head.php .
But this did not work. The php code did not get parsed.

User avatar
pentapenguin
Former Team Member
Posts: 11030
Joined: Thu Jul 01, 2004 4:15 am
Location: GA, USA

Re: How to use PHP in phpBB3. All files seem .html

Post by pentapenguin » Tue Nov 06, 2007 7:05 pm

You can add your PHP code to the .html template files but you need to first go to your ACP -> General -> Security settings -> Allow php in templates = Yes Be sure to clear your cache after you make that change.
Support Resources: Support Request Template
If you need professional assistance with your board, please contact me for my reasonable rates.

User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: How to use PHP in phpBB3. All files seem .html

Post by Erik Frèrejean » Tue Nov 06, 2007 7:07 pm

You can use the following example code in your template:

Code: Select all

<!-- PHP -->
echo "hello!";
<!-- ENDPHP -->  
But to make this work you have to enable php in templates (acp -> general -> security settings -> Allow php in templates)
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)

zentropy
Registered User
Posts: 85
Joined: Thu Nov 01, 2007 12:27 am

Re: How to use PHP in phpBB3. All files seem .html

Post by zentropy » Tue Nov 06, 2007 7:29 pm

Should the filenames also be changed from .html to .php ? I have turned on the php setting in the ACP and used the recommended PHP opening and closing tags, though it seems not to work yet after a hard refresh(Ctrl+F5). The PHP code does not get parsed yet.

WorldBeachList
Registered User
Posts: 28
Joined: Thu Feb 03, 2005 5:19 pm
Location: Virginia, USA
Contact:

Re: How to use PHP in phpBB3. All files seem .html

Post by WorldBeachList » Tue Nov 06, 2007 7:45 pm

zentropy wrote:Should the filenames also be changed from .html to .php ? I have turned on the php setting in the ACP and used the recommended PHP opening and closing tags, though it seems not to work yet after a hard refresh(Ctrl+F5). The PHP code does not get parsed yet.
No, do not change the file names.

By "clear the cache" above, they do not mean the browser cache with CTRL-F5. You need to go to ACP and click the "Purge the cache" button at the bottom of the General page. This removes the internally built page cache so that your template changes will be incorporated into what is sent to browsers.

User avatar
djp2
Registered User
Posts: 27
Joined: Wed Nov 15, 2006 2:02 am
Contact:

Re: How to use PHP in phpBB3. All files seem .html

Post by djp2 » Wed Nov 07, 2007 4:55 am

zentropy wrote:Should the filenames also be changed from .html to .php ? I have turned on the php setting in the ACP and used the recommended PHP opening and closing tags, though it seems not to work yet after a hard refresh(Ctrl+F5). The PHP code does not get parsed yet.
you might need some .htaccess magic to tell apache that it can parse the .html to look for php commands.

something like the following might work ;

Code: Select all

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

User avatar
pentapenguin
Former Team Member
Posts: 11030
Joined: Thu Jul 01, 2004 4:15 am
Location: GA, USA

Re: How to use PHP in phpBB3. All files seem .html

Post by pentapenguin » Wed Nov 07, 2007 5:10 am

No, you don't need to do anything other than enable PHP in the ACP and clear the cache. The suggestions to rename the files and add an .htaccess file will only cause problems.
Support Resources: Support Request Template
If you need professional assistance with your board, please contact me for my reasonable rates.

zentropy
Registered User
Posts: 85
Joined: Thu Nov 01, 2007 12:27 am

Re: How to use PHP in phpBB3. All files seem .html

Post by zentropy » Wed Nov 07, 2007 2:17 pm

WorldBeachList wrote:
zentropy wrote:Should the filenames also be changed from .html to .php ? I have turned on the php setting in the ACP and used the recommended PHP opening and closing tags, though it seems not to work yet after a hard refresh(Ctrl+F5). The PHP code does not get parsed yet.
No, do not change the file names.

By "clear the cache" above, they do not mean the browser cache with CTRL-F5. You need to go to ACP and click the "Purge the cache" button at the bottom of the General page. This removes the internally built page cache so that your template changes will be incorporated into what is sent to browsers.
Thanks, that did the trick and seemed to be the last step to get it all working. Thanks guys.

PS: These forums are quite helpful if i may say so. ;)

Locked

Return to “[3.0.x] Support Forum”