Topic: Website Integration if() in PHP

Hi!

I am working on website integration and read your article on it at http://www.punbb.org/docs/dev.html.
However, I would like to know if there is an IF statement possible to be used to switch text from "Welcome, username!" to "Welcome, you are not logged in." and link them to the login page etc.

For example, is there something like:

if($punbb['session_logged_in']) {
// Functions if they are logged in
}
else {
// Functions if they're not
}

If this code is possible, will someone please give it to me? It would be greatly appreciated.
Also, on a side note, is anything used within the $pun_user exactly what is in the punbb_users table structure in MySQL?

Thank you!

Re: Website Integration if() in PHP

$pun_user['is_guest'] is what you're looking for.
And yes, if you look at the query to populate $pun_user we fetch users.*, groups.*, and a couple columns from the online table.

Re: Website Integration if() in PHP

So do I just use "isset" for that?
if (isset($pun_user['is_guest'])
or do I need to use something like
if ($pun_user['is_guest'] = "TRUE") ?

Re: Website Integration if() in PHP

$pun_user['is_guest'] is a boolean, its value tells you whether the user is or is not a guest.
btw, if ($pun_user['is_guest'] = "TRUE") should be if ($pun_user['is_guest'])
(= is assignment, == is comparison, "TRUE" is a string and not the boolean true)

5 (edited by joshedgar 2008-01-05 15:39)

Re: Website Integration if() in PHP

Smartys:

Below is the code I am using but it is not working. It just simply shows the text from my "if true" -- no matter if they are or are not logged in.

<?php
define('PUN_ROOT', './forums/');
define('PUN_TURN_OFF_MAINT', 1);
require PUN_ROOT.'include/common.php';

if($pun_user['is_guest'] == "TRUE")
    {
    echo "Welcome! Please log in or register to see your stats. <a href=\"/forums/login.php\">Log In</a> · <a href=\"/forums/register.php\">Register</a>";
    }
else
    {
    echo "Hello, <strong>".pun_htmlspecialchars($pun_user['username'])."</strong>.  Class: <strong>".pun_htmlspecialchars($pun_user['title'])."</strong>  Posts: <strong>".pun_htmlspecialchars($pun_user['num_posts'])."</strong>";
    }
?>

Re: Website Integration if() in PHP

That's because "TRUE" is a string. Not a boolean. So, comparing a boolean to a string like that fails.
The line should just be if ($pun_user['is_guest']), or, if you insist, if ($pun_user['is_guest'] == true)

Re: Website Integration if() in PHP

It's still not working, using EITHER of:

if($pun_user['is_guest'])

or

if($pun_user['is_guest'] == true)

??

Re: Website Integration if() in PHP

What's not working about it? And could you provide a link to your site?

Re: Website Integration if() in PHP

http://www.simpletorrents.org/forums/

It just displays as if you're still a guest. Even if you are logged in.

Re: Website Integration if() in PHP

Also, now I have a new error there that says check_cookie is being redeclared?

Re: Website Integration if() in PHP

Okay, sorry for the triple posting here, but I think I got it to work. It was mad because I was including common.php twice -- e.g. it was working on the site itself, which I wasn't checking, but wasn't working on the forums. It now works, except the "Class:" shows no Title. How can you pull the title of their usergroup? Thank you.

Re: Website Integration if() in PHP

$pun_user['g_title']
Like I said, $pun_user has entries for all of the columns in the users table and the groups table.

Re: Website Integration if() in PHP

I used g_user_title...I guess that works too?

And, hopefully last question. I put a log out button IF they are logged in on my site, using $pun_user['id'] to replace the id variable in the link.
But, when clicked, it just redirects back to the forums -- where it says You are not allowed to view the forums (because I set guests to not be able to.)
Can I make it redirect back to the page it was clicked from, like, a page on my main site? I can use PHP $_SERVER to get the path it's at, if that's neccesary.

Thanks.

Re: Website Integration if() in PHP

joshedgar wrote:

I used g_user_title...I guess that works too?

One is the name of the group, the other is the forum tag. So whichever you prefer wink

joshedgar wrote:

And, hopefully last question. I put a log out button IF they are logged in on my site, using $pun_user['id'] to replace the id variable in the link.
But, when clicked, it just redirects back to the forums -- where it says You are not allowed to view the forums (because I set guests to not be able to.)
Can I make it redirect back to the page it was clicked from, like, a page on my main site? I can use PHP $_SERVER to get the path it's at, if that's neccesary.

You'll need to edit login.php to redirect somewhere other than index.php. Not difficult though.

Re: Website Integration if() in PHP

Make sure you set the cookie domain in the config.php file. I had to do that in order to make mine work.

Re: Website Integration if() in PHP

PhaxeNor wrote:

Make sure you set the cookie domain in the config.php file. I had to do that in order to make mine work.

That's not required in most cases and can cause problems if set improperly. Since everything seems to be working properly at this point, he shouldn't really mess with it.