UBB.Dev
Posted By: SitStay Type Conversion Bug - 08/07/2001 4:06 AM
Hi Scream,

Fix for weird language file names (at least in the logout.php routine). It might be happening elsewhere too.

In logout.php t he line
$user[loggedout] = 1;
should be
$user['loggedout'] = "1";

I have put some gettype commands in main.inc.php so I can see what is happening. When I execute logout.php from the command line (I am logged out already, no cookies), $user will have a type of "string" instead of "array" when it comes into send_header in main.inc.php. Very weird.

When this happens $user[newlanguage] is equal to "1" or "s" or whatever it grabs from memory. This causes problems with the language files because now it uses that instead of english or whatever.

$user['loggedout'] = "1"; fixes it.

I hope this helps!
Posted By: Rick Re: Type Conversion Bug - 08/07/2001 3:45 PM
Thanks for the info. Will get that changed over.
Posted By: SitStay Re: Type Conversion Bug - 08/10/2001 2:09 PM
I put 5.4.3 into production and this Type Conversion problem bit me again. It seems that typing is a problem with the $user variable which might need to be explored in greater depth. I put gettype statements in the send_header routine and found the type for $user isn't always the array but we expect it to be.

In main.inc.php's send_header routine, I was getting stylesheets not found because they were coming up "/stylesheet/1.css".

When I was testing I found that in the logout.php routine sets the $user[loggedout] flag to 1 right before sending calling send_header. In my original tests, changing this to [:blue]$user['loggedout'] = "1"; kept the type as array in the send_header routine. But when I moved the files into production, the problem crept back in. I could run the exact same program files in one directory and I'd get the error. But in another directory I wouldn't. It seems type is still a problem. So here is what I did to correct it once and for all.

In the send_header routine, I added an if statement to verify that $user is actually an array. Because of the typing problem, sometimes it is Boolean and sometimes it is a string. In those cases this section will cause problems. But also in those cases, none of the fields in this section are set so bypassing them doesn't cause problems. My additions are in blue.

[:blue]if ( is_array($user) ) {
// -----------------------------
// Grab any personal preferences
$FrontPage = $user[U_FrontPage];
$Privates = $user[U_Privates];
$StyleSheet= $user[U_StyleSheet];
$Status = $user[U_Status];
if ($user[newlanguage]) {
require ("$config[path]/languages/$user[newlanguage]/generic.php");
}
[:blue]}

This has solved the problem and I am no longer seeing the stylesheet errors.

Posted By: Rick Re: Type Conversion Bug - 08/10/2001 4:53 PM
Thanks for the info. I'm going to spend some time and change the majority of the arrays to the ['key'] type instead of the [key], at least the ones that seem to be causing some problems currently.
© UBB.Developers