开发者

Appending index value to duplicate screen names

I'm using expressionengine as a CMS but want to override the core validation for new users. When someone registers as a new user, the system checks to 开发者_开发百科see if the screen_name is already taken. If it is, then it throws an error flag.

I've found the section of code that's doing the validation but I'd like to change it so that instead of throwing and error the screen_name is appended with a space and number (one above the count value.

So "John Smith" gets changed to "John Smith 3" (assuming there are two other "John Smith" screen_names in the db).

How can I modify this code to acheive this?

        /** -------------------------------------
        /**  Is screen name taken?
        /** -------------------------------------*/

        if (strtolower($this->cur_screen_name) != strtolower($this->screen_name))
        {
            $query = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name = '".$DB->escape_str($this->screen_name)."'");

            if ($query->row['count'] > 0)
            {                            
                $this->errors[] = $LANG->line('screen_name_taken');
            }
        }


if (strtolower($this->cur_screen_name) != strtolower($this->screen_name))
{
    $query = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name = '".$DB->escape_str($this->screen_name)."'");

    if ($query->row['count'] > 0)
    {   
        $query2 = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name LIKE '".$DB->escape_str($this->screen_name)."'");
        $name = $DB->escape_str($this->screen_name).$query2->row['count']; 
        $this->errors[] = 'The screen name you choose is taken please use '.$name.' for your new  screen_name);
    }
}

Have fun!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜