Firefox PHP

Quick Authentication

Posted by Brian Moon 
Re: Quick Authentication
June 14, 2009 07:46PM
Understood.

I just replaced my errant print statement with the print_r statement and it spit out everything having to do with my account. I now know it's not quick_auth.php. I will continue to trace the problem.

Thanks for your help thus far.
Re: Quick Authentication
June 14, 2009 07:54PM
Wow. Here was the problem the whole time.

Wrong
if($USER["user_id"]){
    echo "logged in";
} else {
    echo "logged out";
}

Right
if($GLOBALS['USER']['user_id']){
    echo "logged in";
} else {
    echo "logged out";
}

That's what I get for copy/pasting code and not paying attention.
Re: Quick Authentication
June 15, 2009 06:25AM
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:

Language: PHP
global $USER;   if($USER["user_id"]){ echo "logged in"; } else { echo "logged out"; }


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
nds
Re: Quick Authentication
October 28, 2009 06:47AM
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!
Re: Quick Authentication
October 28, 2009 06:52AM
I doubt that this is the provider's doing.
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
my blog linkedin profile secret sauce



Edited 1 time(s). Last edit at 10/28/2009 06:53AM by Maurice Makaay.
nds
Re: Quick Authentication
October 28, 2009 07:20AM
Quote
Maurice Makaay
I doubt that this is the provider's doing.
Please check what the output of this is:

root
Re: Quick Authentication
October 28, 2009 08:04AM
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
nds
Re: Quick Authentication
October 28, 2009 08:39AM
Hm, very curious. I could swear to high heaven, that I changed nothing, what could cause this. Should I be worried about it?

Btw: Thank you for your fast support, the problem is solved by changing the name of the variable.
Re: Quick Authentication
October 28, 2009 08:50AM
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
nds
Re: Quick Authentication
October 28, 2009 10:27AM
My provider said, that this is probably a behaviour of the recently installed php5 version
Sorry, only registered users may post in this forum.

Click here to login