Creating custom html template with a custom .php file

For support and discussion related to templates, themes, and imagesets in phpBB 3.2.
Post Reply
Chappie
Registered User
Posts: 21
Joined: Fri Jan 26, 2018 3:52 am

Creating custom html template with a custom .php file

Post by Chappie » Wed Apr 04, 2018 8:55 pm

Hey!

I want to create my own custom html-template with a custom .php-file.

But when I include overall_header.html & overall_footer.html - the page goes totally white with the text from the .php file, but I have no colors...just a white page.

The text from the copyright-part from the overallt_footer.html and some form av very primitive navigation-bar at the top is also showing up by the way.

My code is:

html:

Code: Select all

<!-- INCLUDE overall_header.html --> 

<p>{TEST1}</p></br>
<p>{TEST2}</p></br>
	
<!-- INCLUDE overall_footer.html -->
.php

Code: Select all


<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$template->assign_vars(array(
	'TEST1'	=> "test1",
	'TEST2'	=> "test2")
);

#page_header('Title Here');

$template->set_filenames(array(
    'body' => 'test.html',
)); 

page_footer();

?>
I thought that my page would have the same style/layout/colors as the style I'm running on.

What am I doing wrong?
I'm totally new with this.

User avatar
eeji
Jr. Style Validator
Posts: 881
Joined: Fri Dec 12, 2008 9:08 pm
Location: Manchester, UK
Contact:

Re: Creating custom html template with a custom .php file

Post by eeji » Wed Apr 04, 2018 10:53 pm

In your php file, remove the # from #page_header('Title Here');

Chappie
Registered User
Posts: 21
Joined: Fri Jan 26, 2018 3:52 am

Re: Creating custom html template with a custom .php file

Post by Chappie » Sun Apr 08, 2018 3:15 am

eeji wrote:
Wed Apr 04, 2018 10:53 pm
In your php file, remove the # from #page_header('Title Here');
Thank you, that totally did it!

But, the page title, where can I see it? I might be blind, but I can't see the page title showing up anywhere in the browser. And what is it's purpose and what does it actually do?

User avatar
eeji
Jr. Style Validator
Posts: 881
Joined: Fri Dec 12, 2008 9:08 pm
Location: Manchester, UK
Contact:

Re: Creating custom html template with a custom .php file

Post by eeji » Sun Apr 08, 2018 2:39 pm

The page title is what shows at the top of your browser, eg. this page shows "phpBB - Creating custom html template with a custom .php file"

Chappie
Registered User
Posts: 21
Joined: Fri Jan 26, 2018 3:52 am

Re: Creating custom html template with a custom .php file

Post by Chappie » Mon Apr 16, 2018 1:55 am

eeji wrote:
Sun Apr 08, 2018 2:39 pm
The page title is what shows at the top of your browser, eg. this page shows "phpBB - Creating custom html template with a custom .php file"
Ok, I see.

I'm also trying to print some user attributes, such as username. But it always says "Anonymous" although I'm logged in. What am I doing wrong?

I've also tried to:
global $user;

etc, but that doesn't change anything, it still won't give me the user attributes.

PHP:

Code: Select all

<?php

define('IN_PHPBB', true);
$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);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$username = $user->data["username"];

$template->assign_vars(array(
'TEST1'	=> $username,
'TEST2'	=> "test2",
'TEST3'	=> "test3")
);

page_header('Test');

$template->set_filenames(array(
    'body' => 'test.html',
)); 

page_footer();

?>
HTML:

Code: Select all

<!-- INCLUDE overall_header.html --> 

<p>hello {TEST1}</p></br>
<p>hello {TEST2}</p></br>
<p>hello {TEST3}</p></br>

</div>
<!-- INCLUDE overall_footer.html -->
If I try to get the user's primary group it says "1" which is the group of Guest/Anonymous.
$group = $user->data["group_id"];

EDIT:
when I navigate to the php file in the browser I just type /test.php
But I guess that I'm missing the session ID and that's what causing all errors with the user attributes?

So how do I get the session ID, and can I get the session ID in my php-file or does it have to be in the url? like this /test.php?1234567890 ? and how do I get the SID to stick to the url ?

- and, what is the Session ID made of? is it some hash sum of something?
- and is the SID bound to the IP-address?
- and, what happens if several users have the same IP-adress (running some form av ip-anonymizer, cloudflare, proxy, etc). Would that be a security flaw/issue?

Thankful for some easy beginner's pointers :)

User avatar
david63
Jr. Extension Validator
Posts: 14724
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Creating custom html template with a custom .php file

Post by david63 » Mon Apr 16, 2018 5:34 am

Are you logged in when you run your script? If not then it is correctly showing you as "Anonymous".
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Chappie
Registered User
Posts: 21
Joined: Fri Jan 26, 2018 3:52 am

Re: Creating custom html template with a custom .php file

Post by Chappie » Mon Apr 16, 2018 7:46 pm

david63 wrote:
Mon Apr 16, 2018 5:34 am
Are you logged in when you run your script? If not then it is correctly showing you as "Anonymous".
Yes, I'm definitly logged in.

But when running the skript I just enter /test.php in the browser and then it says "Anonymous".

But if I copy the SID and paste it on the URL like this: /test.php?sid=1234567890
Then the script actually works and spells out the correct username.

But for this to work I have to manually copy the SID and paste it to the URL and that can't possibly be the right way to go.

So how do I run the script correctly without having to coping and pasting the SID to the URL?

Session id & security flaw?
And about the session id, could someone steal my session by generating the same SID and get admin access by simply pasting the SID to any url in the forum?

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51347
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Creating custom html template with a custom .php file

Post by Brf » Mon Apr 16, 2018 7:57 pm

That means your cookie settings are wrong. The SID should be stored in your cookie.
Nobody can steal your session because they would not know your SID.

User avatar
eeji
Jr. Style Validator
Posts: 881
Joined: Fri Dec 12, 2008 9:08 pm
Location: Manchester, UK
Contact:

Re: Creating custom html template with a custom .php file

Post by eeji » Mon Apr 16, 2018 9:58 pm

There are two ways I'm aware of to get a users SID (there may be others, but I'm not too well up on the core code). In php files you can use the append_sid() function (more details here: https://wiki.phpbb.com/Function.append_sid ), or if its hard coded links in your custom html template files you can use {SID} after a url, eg: http://example.com/custom-page.php{SID}
Both these methods will only add the session ID if it cannot be obtained from the cookie.

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51347
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Creating custom html template with a custom .php file

Post by Brf » Mon Apr 16, 2018 10:36 pm

There is no need for that if the board cookies are correct.

Chappie
Registered User
Posts: 21
Joined: Fri Jan 26, 2018 3:52 am

Re: Creating custom html template with a custom .php file

Post by Chappie » Tue Apr 17, 2018 5:57 am

Brf wrote:
Mon Apr 16, 2018 7:57 pm
That means your cookie settings are wrong. The SID should be stored in your cookie.
Nobody can steal your session because they would not know your SID.
What's the cookie settings supposed to be?

Here's my current settings:

Cookie name: phpbb3_hvc3n
This can be anything what you want, make it original. Whenever the cookie settings are changed the name of the cookie should be changed.

Cookie path: /
This will usually be the same as your script path or simply a slash to make the cookie accessible across the site domain.

Cookie secure: Disabled
If your server is running via SSL set this to enabled else leave as disabled. Having this enabled and not running via SSL will result in server errors during redirects.
Enabled Disabled

Cookie notice: Disabled
If enabled a cookie notice will be displayed to users when visiting your board. This might be required by law depending on the content of your board and enabled extensions.
I'm running the server with SSL, should I have "Cookie secure" set to Enabled ?
And what's the difference beteeen Cookie secure: disabled and enabled? what does this actually do?

When I'm experimenting I'm just running a copy of the forum & database on a local VM if that's something that would matter beteen a LIVE site and a local site on the VM.

---------------------
Regarding append_sid() :
How do I get the current SID from the logged in user so I can append it to the URL in the browser?

when trying to append the sid I just get a different SID each time I refresh the page test.php
and it still says Anonymous because it's not the SID on the used I logged in with.

I'm just entering the page /test.php manually in the browser when running the script.

User avatar
Mick
Support Team Member
Support Team Member
Posts: 20110
Joined: Fri Aug 29, 2008 9:49 am
Location: Cardiff

Re: Creating custom html template with a custom .php file

Post by Mick » Tue Apr 17, 2018 7:58 am

"The more connected we get the more alone we become" - Kyle Broflovski

There are no ‘threads’ in phpBB, they are topics.

Post Reply

Return to “[3.2.x] Styles Support & Discussion”

Who is online

Users browsing this forum: alhitary and 8 guests