Quick Authentication
Posted by Brian Moon
Re: Quick Authentication June 14, 2009 07:46PM |
Registered: 16 years ago Posts: 12 |
Re: Quick Authentication June 14, 2009 07:54PM |
Registered: 16 years ago Posts: 12 |
June 15, 2009 06:25AM |
Admin Registered: 20 years ago Posts: 8,532 |
It looks like that code is inside some function or so then, where the global variable $USER is not visible ("out of scope"). What you could do for easier code writing (especially when you are using $USER repeatedly), is globalizing $USER before using it:
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Language: PHPglobal $USER; if($USER["user_id"]){ echo "logged in"; } else { echo "logged out"; }
Maurice Makaay
Phorum Development Team



Re: Quick Authentication October 28, 2009 06:47AM |
Registered: 15 years ago Posts: 4 |
Quote
Maurice Makaay
That is a lot less that what you stated above. If it's only the hello part that you need, then after including the quick authentication code you can use something like this (untested code):
<?php if ( isset($GLOBALS['USER']) && !empty($GLOBALS['USER']['user_id']) ) { $display_name = htmlspecialchars($GLOBALS['USER']['display_name']); print "Hello, $display_name!"; } else { print "Hello, world!"; } ?>
Hi Maurice,
the code you recommendet worked fine for the last year. But since a few days it produces "Hello, r!", when i am not logged in. I changed nothing, perhaps the provider did an php update.
Thanx for your suppestions!
October 28, 2009 06:52AM |
Admin Registered: 20 years ago Posts: 8,532 |
I doubt that this is the provider's doing.
Please check what the output of this is:
My guess is that some code sets $USER to a string (like "richard") and that $GLOBALS['USER']['user_id'] therefore translates to the first character in that string
(Since $USER is not an array but a string in this case, the 'user_id' will translate to an integer 0 (zero), which points at the first character in the string)
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Edited 1 time(s). Last edit at 10/28/2009 06:53AM by Maurice Makaay.
Please check what the output of this is:
Language: PHP<?php print "<xmp>"; print_r($GLOBALS[';USER';]); print "</xmp>"; ?>
My guess is that some code sets $USER to a string (like "richard") and that $GLOBALS['USER']['user_id'] therefore translates to the first character in that string
(Since $USER is not an array but a string in this case, the 'user_id' will translate to an integer 0 (zero), which points at the first character in the string)
Maurice Makaay
Phorum Development Team



Edited 1 time(s). Last edit at 10/28/2009 06:53AM by Maurice Makaay.
Re: Quick Authentication October 28, 2009 07:20AM |
Registered: 15 years ago Posts: 4 |
October 28, 2009 08:04AM |
Admin Registered: 20 years ago Posts: 8,532 |
Heh, "root" was the example that I first had in mind, but I decided to go for "richard" to make it less geeky ;-)
Whatever the case is here, it is not the Phorum code that is messing up the $USER variable. There's some other code on your system that is doing this. Most probably some new code that was added recently, if this behavior started only recently.
One thing that you can do, is change the quick authentication script by substituting all USER occurrences with PHORUMUSER or so. After doing that, you can use $GLOBALS['PHORUMUSER'] in your scripts instead of $GLOBALS['USER'].
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Whatever the case is here, it is not the Phorum code that is messing up the $USER variable. There's some other code on your system that is doing this. Most probably some new code that was added recently, if this behavior started only recently.
One thing that you can do, is change the quick authentication script by substituting all USER occurrences with PHORUMUSER or so. After doing that, you can use $GLOBALS['PHORUMUSER'] in your scripts instead of $GLOBALS['USER'].
Maurice Makaay
Phorum Development Team



Re: Quick Authentication October 28, 2009 08:39AM |
Registered: 15 years ago Posts: 4 |
October 28, 2009 08:50AM |
Admin Registered: 20 years ago Posts: 8,532 |
I don't know if you should be worried. Some code on your website is setting $USER to value "root". I have no insight whatsoever in what code would be doing that. I can therefore not tell you whether you should be worried or not.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
Maurice Makaay
Phorum Development Team



Re: Quick Authentication October 28, 2009 10:27AM |
Registered: 15 years ago Posts: 4 |
Sorry, only registered users may post in this forum.