Php User Variables

Temporary forum to obtain support for MODs/Styles while phpbb.com is down
Locked
WinterWulf
Registered User
Posts: 14
Joined: Wed Feb 04, 2009 6:35 pm
Location: North Pole

Php User Variables

Post by WinterWulf » Tue Feb 10, 2009 5:07 am

I've been trying to use variables from
http://phpbbcom.phpbbservice.nl/kb/arti ... ables.html
in the _body file of one of my custom PhpBB integrated pages; the problem is that they keep returning empty. On the page listed above they said that the follow code would work:

Code: Select all

echo $userdata['username'];
The code I am using is this:

Code: Select all

<!-- PHP -->
echo "Hello".$userdata['username']."! Your user ID is".$userdata['user_id']."!";
<!-- ENDPHP -->
This, of course, ends up returning:
Hello! Your user ID is!
It would seem that the vars are dumped before the _body file is read - or that PhpBB just won't read them from the template pages.

WinterWulf
Registered User
Posts: 14
Joined: Wed Feb 04, 2009 6:35 pm
Location: North Pole

Re: Php User Variables

Post by WinterWulf » Tue Feb 10, 2009 8:31 am

viewtopic.php?f=26&t=12672&start=150
geckzilla wrote: Re: Templating ... a simple guide
by geckzilla » Sun Sep 30, 2007 5:10 am

... ... ...

...I thought the <!--PHP--> tags would be a godsend but as it turns out you can't include phpbb variables within the php tags.
Judging by the date on this post I'd say it's not for PhpBB3.4 (it seems to be for 2.2) but it may still be pertinant.

I hope not since I still don't understand what those templates actualy say or how they are realy set up. I'd realy like to be able to take care of this in php.

WinterWulf
Registered User
Posts: 14
Joined: Wed Feb 04, 2009 6:35 pm
Location: North Pole

Re: Php User Variables

Post by WinterWulf » Tue Feb 10, 2009 11:29 pm

Alright, I've been working on this around the clock without much success. Here are some updates:
  • :idea: Php variables do work in template files (which means the above quote only applyed to PhpBB2)

    :idea: I had assumed that since all the files were compiled and catched before being run that I wouldn't need to worry about certain variables not being global. Since things still arn't working I've been trying to find where the variables are in the script itself to turn it into a global variable. If that fails, I'm going to try calling it ahead of time in configuration.php and see if anything starts to smoke (yes, I do know that is says not to touch it but I'm sure it's one of the first scripts to be run so it's the "safest" bet :) )

    :idea: The variable I am using was taken from an old PhpBB2 post (not PhpBB3 as I had thought) and may very well be incorrect.
I'll just start editing this post below for any minor facts I find so this thread doesn't turn into my personal blog on PhpBB's php vars.

WinterWulf
Registered User
Posts: 14
Joined: Wed Feb 04, 2009 6:35 pm
Location: North Pole

Re: Php User Variables

Post by WinterWulf » Thu Feb 12, 2009 2:49 am

*sigh* All that time searching and the answer was in the var:

Code: Select all

$user->data['username'];

No fancy tricks or anything- I deconstructed a MOD to get it. Realy wish I found it sooner.

For those who don't know, you have to assign $userdata['username']; to a var (like $a_username) before you use it in something like a MySQL query.
Hope this helps someone.

Locked