group_user_add gives log_ip null error

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
kenno
Registered User
Posts: 81
Joined: Sun Apr 09, 2006 10:54 am
Location: Estonia
Contact:

group_user_add gives log_ip null error

Post by kenno »

Its a custom made mod which enters certain users to certain group, but when I submit someone then I get log_ip null error. As a matter of fact submitting itself is working when I refresh the page but that error annoys.

Function:

Code: Select all

if ($submit)
{
    $error = array();
    
    if(!$auth->acl_get('a_'))
    {
        $error[] = 'Puuduvad vastavad õigused';
    }
        
    $sql = 'SELECT count(*), user_id
        FROM ' . USERS_TABLE . '
        WHERE username_clean = "' . strtolower($username) . '"';
    $user = $db->sql_query($sql);
    $user = $db->sql_fetchrow($user);
        
    if ($user['count(*)'] == 0)
    {
        $error[] = 'Kasutajat ei eksistreeri';
    }
        
    if (is_numeric($nr) == false)
    {
        $error[] = 'See ei ole number';
    }
        
    if (count($error) == 0)
    {
        $db->sql_query('UPDATE ' . USERS_TABLE . '
                SET user_klubikaart = "' . $nr . '"
                WHERE username_clean = "' . strtolower($username) . '"');

        group_user_add($group_id, (int) $user['user_id'], false, false, true);
        header('Location: '.append_sid($phpbb_root_path.'ct.'.$phpEx));
    }
    else
    {
        $error_formed = '';
        $first = true;
        foreach ($error as $row)
        {
            $error_formed .= ($first ? '' : '<br />').$row;
            $first = false;
        }
    }
} 
Gives error:
Image

How can i bypass or remove this error?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52075
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: group_user_add gives log_ip null error

Post by Brf »

That is saying you are not logged in when you are running the script.
User avatar
kenno
Registered User
Posts: 81
Joined: Sun Apr 09, 2006 10:54 am
Location: Estonia
Contact:

Re: group_user_add gives log_ip null error

Post by kenno »

That LOG_IP is not important to me, can I just force to set that log_ip in that function to remove this error?
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: group_user_add gives log_ip null error

Post by Erik Frèrejean »

Simply add the three phpBB session lines and the error disappears. That IP is stored in the user object and as you don't initialise that object the error is triggered.
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
User avatar
kenno
Registered User
Posts: 81
Joined: Sun Apr 09, 2006 10:54 am
Location: Estonia
Contact:

Re: group_user_add gives log_ip null error

Post by kenno »

Code: Select all

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup(); 
I have that on my file header already. :?
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: group_user_add gives log_ip null error

Post by Erik Frèrejean »

Should be correct than, please post all related code.
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
User avatar
kenno
Registered User
Posts: 81
Joined: Sun Apr 09, 2006 10:54 am
Location: Estonia
Contact:

Re: group_user_add gives log_ip null error

Post by kenno »

Just in case, the whole file:

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
 
page_header('Klubiliste nimekiri');

$group_id    = 9905;
$submit        = request_var('ct_submit', false);
$username     = isset($_POST['ct_username']) ? $_POST['ct_username'] : null;
$nr         = isset($_POST['ct_nr']) ? $_POST['ct_nr'] : null;

$sql = "SELECT *
    FROM " . USER_GROUP_TABLE . " AS user_group_table
    LEFT JOIN " . PROFILE_FIELDS_DATA_TABLE . " AS fields_table ON fields_table.user_id = user_group_table.user_id
    LEFT JOIN " . USERS_TABLE . " AS users_table ON users_table.user_id = user_group_table.user_id
    WHERE user_group_table.group_id = '{$group_id}'
    ORDER BY users_table.user_klubikaart ASC";
$result = $db->sql_query($sql);


while($row = $db->sql_fetchrow($result))
{
        $uid = $bitfield = $options = '';
        $allow_bbcode = $allow_urls = $allow_smilies = true;
        generate_text_for_storage($row['pf_auto'], $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
        $relv = generate_text_for_display($row['pf_auto'], $uid, $bitfield, $options);
        if ( $row['user_klubikaart'] == 0 )
             $row['user_klubikaart'] = '?';
    $template->assign_block_vars('row', array(
        'NR'         => $row['user_klubikaart'],
        'USERNAME'    => $row['username'],
        'AUTO'    => $relv,
        'ASUKOHT'    => $row['user_from'],
        'U_USERNAME'    => append_sid($phpbb_root_path.'memberlist.'.$phpEx, 'mode=viewprofile&u='.$row['user_id']),
        'U_EDIT'    => append_sid($phpbb_root_path.'ct.'.$phpEx, 'edit='.base64_encode(serialize(array($row['username'], $row['user_klubikaart'])))),
    ));
}

if ($submit)
{
    $error = array();
    
    if(!$auth->acl_get('a_'))
    {
        $error[] = 'Puuduvad vastavad õigused';
    }
        
    $sql = 'SELECT count(*), user_id
        FROM ' . USERS_TABLE . '
        WHERE username_clean = "' . strtolower($username) . '"';
    $user = $db->sql_query($sql);
    $user = $db->sql_fetchrow($user);
        
    if ($user['count(*)'] == 0)
    {
        $error[] = 'Kasutajat ei eksistreeri';
    }
        
    if (is_numeric($nr) == false)
    {
        $error[] = 'See ei ole number';
    }
        
    if (count($error) == 0)
    {
        $db->sql_query('UPDATE ' . USERS_TABLE . '
                SET user_klubikaart = "' . $nr . '"
                WHERE username_clean = "' . strtolower($username) . '"');

        group_user_add($group_id, (int) $user['user_id'], false, false, true);
        header('Location: '.append_sid($phpbb_root_path.'ct.'.$phpEx));
    }
    else
    {
        $error_formed = '';
        $first = true;
        foreach ($error as $row)
        {
            $error_formed .= ($first ? '' : '<br />').$row;
            $first = false;
        }
    }
}

$edit = isset($_GET['edit']) ? @unserialize(base64_decode($_GET['edit'])) : '';

$template->assign_vars(array(
    'IS_ADMIN'    => $auth->acl_get('a_') ? true : false,
    'ERROR'        => isset($error_formed) ? $error_formed : false,
    'USERNAME'    => isset($edit[0]) ? $edit[0] : null,
    'NR'        => isset($edit[1]) ? $edit[1] : null,
));


$template->set_filenames(array(
        'body' => 'ct_body.html',
));
 
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
 
?>
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: group_user_add gives log_ip null error

Post by Erik Frèrejean »

/me is stupid that I've missed this:

Code: Select all

$sql = 'SELECT count(*), user_id
        FROM ' . USERS_TABLE . '
        WHERE username_clean = "' . strtolower($username) . '"';
    $user = $db->sql_query($sql);
    $user = $db->sql_fetchrow($user); 
You are overwriting the $user variable which holds the phpBB user object. Rename that variable and the problem should be resolved.
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
User avatar
kenno
Registered User
Posts: 81
Joined: Sun Apr 09, 2006 10:54 am
Location: Estonia
Contact:

Re: group_user_add gives log_ip null error

Post by kenno »

Great support!
Solved! ;)
Locked

Return to “[3.0.x] MOD Writers Discussion”