1
joostmusic
New block with user check
  • 2004/9/1 12:04

  • joostmusic

  • Just popping in

  • Posts: 9

  • Since: 2004/8/26


Hi all,

I try to install a new (PHP) block in which I'll show different text according to if a user is logged in or not. I looked into some of the forum posts and so far I came up with this:

include "/mainfile.php";

if ( 
$xoopsUser ) {
   echo 
'Welcome to this page!';
} else {
   echo 
'Register now!';
}


However, this does not work; it always displays 'Register now!'. How do I fix this?

2
Mithrandir
Re: New block with user check

Drop the mainfile.php - it is already included.

Next thing to understand is that the code in the custom PHP block is executed in a function scope and therefore needs global variables to be declared global before use.

global $xoopsUser;
if (
$xoopsUser) {
    echo 
'Welcome to this page!';
}
else {
    echo 
'Register now!';
}

3
joostmusic
Re: New block with user check
  • 2004/9/1 16:54

  • joostmusic

  • Just popping in

  • Posts: 9

  • Since: 2004/8/26


This worked, thanks! Took me a while that there was an additional apostrophe in my intro text (It's free) so it wouldn't work, but after a trailing backslash everything was fine.

If anyone's interested: http://www.joostmusic.nl

Login

Who's Online

277 user(s) are online (185 user(s) are browsing Support Forums)


Members: 0


Guests: 277


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits