Topic: error on guest login

upgraded to 1.2 and 1.21 installed trell's mod email-digest it all runs fine but I just noticed that when logging as a guest I get this  error
Notice: Undefined variable: remote_address in /home/user/public_html/ww2/include/functions.php on line 676

Notice: Undefined variable: remote_address in /home/user/public_html/ww2/include/functions.php on line 697

any hint ?

Re: error on guest login

Erm, what are those lines in your code?

Re: error on guest login

Hmm, that can't be right. Line 676 is a blank line in PunBB 1.2.1, but on 675, there's:

$remote_address = $_SERVER['REMOTE_ADDR'];

How that could lead to an "undefined variable" error is however beyond me. Try it with a fresh functions.php from the 1.2.1 download.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: error on guest login

#
#---------[ 12. FIND (line: ~708) ]-------------------------------------------
#

    $remote_address = $_SERVER['REMOTE_ADDR'];


#
#---------[ 13. REPLACE WITH ]------------------------------------------------
#

    $remote_address = isset($_SERVER['SHELL']) ? '127.0.0.1' : $_SERVER['REMOTE_ADDR'];

That's from the email digest code

Re: error on guest login

thanks smartys, that did it !
hell this place is even more reactive than textdrive !

thanks a zill !

-m

Re: error on guest login

I still can't see how what would lead to an undefined variable. Oh well smile

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: error on guest login

Who knows, maybe some other change in the code

Re: error on guest login

argh that did it and so the error message is gone but with it the email-digest too !

Re: error on guest login

How does your get_remote_address() function look now?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

10 (edited by mickael 2005-02-13 23:40)

Re: error on guest login

Smartys wrote:
#


    $remote_address = isset($_SERVER['SHELL']) ? '127.0.0.1' : $_SERVER['REMOTE_ADDR'];

That's from the email digest code

double $ signs doesn't make you richer in php, one leftover $  was an error but it is still there ...

Re: error on guest login

I want to know how the whole function looks. In 1.2.1 it should look like this:

function get_remote_address()
{
    $remote_address = $_SERVER['REMOTE_ADDR'];

    // If HTTP_X_FORWARDED_FOR is set, we try to grab the first non-LAN IP
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
        if (preg_match_all('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $_SERVER['HTTP_X_FORWARDED_FOR'], $address_list))
        {
            $lan_ips = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/', '/^10\..*/', '/^224\..*/', '/^240\..*/');
            $address_list = preg_replace($lan_ips, null, $address_list[0]);

            while (list(, $cur_address) = each($address_list))
            {
                if ($cur_address)
                {
                    $remote_address = $cur_address;
                    break;
                }
            }
        }
    }

    return $remote_address;
}
"Programming is like sex: one mistake and you have to support it for the rest of your life."

12 (edited by mickael 2005-02-13 23:52)

Re: error on guest login

I've redone it from scratch and it was me at fault at some point
the code after the mod looks like

function get_remote_address()
{
    $remote_address = isset($_SERVER['SHELL']) ? '127.0.0.1' : $_SERVER['REMOTE_ADDR'];

    // If HTTP_X_FORWARDED_FOR is set, we try to grab the first non-LAN IP
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    {
        if (preg_match_all('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $_SERVER['HTTP_X_FORWARDED_FOR'], $address_list))
        {
            $lan_ips = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/', '/^10\..*/', '/^224\..*/', '/^240\..*/');
            $address_list = preg_replace($lan_ips, null, $address_list[0]);

            while (list(, $cur_address) = each($address_list))
            {
                if ($cur_address)
                {
                    $remote_address = $cur_address;
                    break;
                }
            }
        }
    }

    return $remote_address;
}

and it seems to behave properly now smile

Re: error on guest login

Rickard wrote:

I still can't see how what would lead to an undefined variable. Oh well smile

it's undefined - because the script is being called by the cronjob and not the browser.  so there's no remote address - and the environment hasn't defined the REMOTE_ADDR.  this doesn't affect the functionality of the code at all - just the warnings being output to the terminal or the log file.


glad you guys got it worked out.

Re: error on guest login

trel1023: Yes, but if $_SERVER['REMOTE_ADDR'] wasn't set, it would lead to an "Undefined index", not "Undefined variable". The variable $remote_address is very much defined even if it has a NULL value.

"Programming is like sex: one mistake and you have to support it for the rest of your life."