...

View Full Version : Another error



Silverflames
10-14-2009, 03:06 PM
I'm getting the following error in my error logs

Undefined variable: username in xxx on line 106

Line 106 shows

$ret = $user->create($username);

What I am trying to do is ldap software called Gallery2. There seem to be many attempts to try and do this. Sadly most suggestions do not work for me. I've got to the stage where I try and login and I get a database error - "An error has occurred while interacting with the database"

I assume this error will be down to the error highlighted in line 106? That is the only error I am getting in my error logs. The full code for this is at http://codex.gallery2.org/LDAP_authentication under Gallery 2.3 if you need to see how this code works.

Thank you for your help, :):)

Fumigator
10-14-2009, 03:41 PM
Looks like the creator of that script made the classic mistake of assuming register_globals would be turned on. You may be able to correct the error by replacing $username with $_POST['username'], but to complicate matters, in other functions the programmer uses the variable $username within different scopes so you have to be careful not to change EVERY occurance of $username.

Bad naming practices imo. Register_globals is so 2004. Biggest mistake of PHP's life.

Silverflames
10-14-2009, 06:30 PM
So if it is being caused by register_globals being turned off, then would turning it on fix the problem? I've just read somewhere that you can turn it on using a .htaccess file. Though it does say it's a security risk so maybe not...

I suppose its always going to be a problem using other peoples code. Everyone seems to tackle the problem a different way. I did think about writing it from scratch, but I'm not really any good with php.

Anyway thanks for your help, I shall have a go at changing the code.

Edit: So the line should now read

$ret = $user->create ($_POST['username']);

Correct?

Silverflames
10-15-2009, 08:22 AM
When I change it to this

$ret = $user->create ($_POST['username']);


I get

Notice: Undefined index: username in /var/www/html/techservices/modules/core/UserLogin.inc on line 106

:(:(:(:(

Fou-Lu
10-15-2009, 09:26 AM
Looks like the creator of that script made the classic mistake of assuming register_globals would be turned on. You may be able to correct the error by replacing $username with $_POST['username'], but to complicate matters, in other functions the programmer uses the variable $username within different scopes so you have to be careful not to change EVERY occurance of $username.

Bad naming practices imo. Register_globals is so 2004. Biggest mistake of PHP's life.

Close, its 2002 when 4.2 was release ;)

Where are you expecting that $username is being set? The problem is simple, its just that there is no $username (and in this example, $_POST['username'] too) set. The solution will be more difficult to determine since it will be dependent entirely on what you have and what you're doing.

Silverflames
10-15-2009, 04:24 PM
Im not entirely sure. Where would it need to be set in the file? :o:o

The person who modified the original code only added in the ldap authentication, you can see where it begins and ends in the file. Outside of that is the original code from the developers.

Am i meant to be using isset or putting $username=$POST['username']

Or am I talking rubbish?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum