1 (edited by Etoile 2009-02-21 16:12)

Topic: How to customize the website homepage and display the visitor username

I was previously using this code in my punbb 1.2 to display a customized welcome message in the homepage of my website:

<h3><p><font size="5">Welcome <?php
define('PUN_ROOT', './forum/');
require PUN_ROOT.'include/common.php';
if($pun_user['username'] == 'Guest'){
echo '';
}
else
{
echo pun_htmlspecialchars($pun_user['username']);
}
 ?> to mysite.fr</font></p></h3>

This displayed

"Welcome to mysite.fr"

if the visitor was not logged in, and

"Welcome user-name to mysite.fr"

when the visitor was logged in. I'm trying to get the same result with my punbb 1.3.2, so I changed the code to:

<h3><p><font size="5">Welcome <?php
define('FORUM_ROOT', './forum/');
require FORUM_ROOT.'include/common.php';
if($pun_user['username'] == 'Guest'){
echo '';
}
else
{
echo pun_htmlspecialchars($pun_user['username']);
}
 ?> to mysite.fr</font></p></h3>

But I get this as html output:

Notice: Undefined variable: pun_user in /web/mysite/www/index.php on line 41

Fatal error: Call to undefined function pun_htmlspecialchars() in /web/mysite/www/index.php on line 46

I created databases with a prefix, so I add the database prefix in the code but it still gives a notice and a fatal error. As I'm using a french language, I'm using "Invité" instead of "Guest" in the code, but it still gives an error. I changed "pun-user" with "pun-users" and it is still the same...

A little help would be much appreciated, thanks smile

2

Re: How to customize the website homepage and display the visitor username

Use $forum_user inplace of $pun_user.

3 (edited by MattF 2009-02-21 17:18)

Re: How to customize the website homepage and display the visitor username

I would also suggest altering that if/else clause from:

if($pun_user['username'] == 'Guest'){
echo '';
}
else
{
echo pun_htmlspecialchars($pun_user['username']);
}

to:

if (!$forum_user['is_guest'])
{
    echo pun_htmlspecialchars($forum_user['username']);
}

The else part is completely unnecessary.


Edit: Just noticed the pun_htmlspecialchars. That has also changed in 1.3. Not sure what that functions new name is, however, so someone else will have to advise you on that bit. smile

Re: How to customize the website homepage and display the visitor username

Thanks, that seems to be a little better, I don't get the php notice anymore, but I still get the fatal error:

Fatal error: Call to undefined function pun_htmlspecialchars() in /web/mysite/www/index.php on line 46

Here is the line 46 of the code:

echo pun_htmlspecialchars($forum_user['username']);

It seems the problem is there... hmm

Re: How to customize the website homepage and display the visitor username

I finally got through this, thanks to you smile

Here is the valid code I used (not sure it's very clean but it is working big_smile ):

<h3><p><font size="5">Welcome <?php
define('FORUM_ROOT', './forum/');
require FORUM_ROOT.'include/common.php';
if($forum_user['username'] == 'Guest'){
echo '';
}
else
{
echo forum_htmlencode($forum_user['username']);
}
 ?> to mysite.fr</font></p></h3>

Many thanks for your help MattF smile

I hope it will be useful for someone else, that's the kind of little thing I like, people surfing the web most often appreciate to have a dedicated welcome homepage wink