Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-06-2008, 07:44 PM
Iskib Iskib is offline
 
Join Date: May 2006
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Quick question with php

Sinario:

I have a banned user table in my database

When a user signs up I want to check the username against this list.

in database banned usernames
test
admin
mod

I can do this with:
Code:
if (mysql_num_rows($ban_username_exists) != '0')
What is I wanted to check if any part of the username exsist in the database.

for example if the user tried to register
test1, test_now, testtaco
admin_me, admin1, adminme
mod1,mod_me,modme

What code would I use to pickup these partials ?
Reply With Quote
  #2  
Old 03-06-2008, 07:48 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$check_ban $db->query_first("SELECT *, COUNT(field) AS 'count FROM banlist
WHERE username = " 
$vbulletin->userinfo['username'] . "
GROUP by field"
);

if(
$check_ban['count'] > 0)
{
//user is banned
exit;

Reply With Quote
  #3  
Old 03-06-2008, 07:55 PM
Iskib Iskib is offline
 
Join Date: May 2006
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey,

Thanks for the quick response. This is for another app not vbulletin.

I know I can check the database for the username entered , but what if they use part of a username that exsist for example admin is banned

what if they try to register admin1 or adminMe
Reply With Quote
  #4  
Old 03-06-2008, 09:13 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use mysql wildcards like this.

[sql]SELECT * FROM banlist WHERE username = '%$username%'[/sql]
Reply With Quote
  #5  
Old 03-06-2008, 10:40 PM
Iskib Iskib is offline
 
Join Date: May 2006
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey,

No that didn't work. It returned for example:

admin as a banned username , but when I tried admin1

it still let admin1 be registered as a user
Reply With Quote
  #6  
Old 03-06-2008, 11:25 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry it should use a like then a equal sign.

[sql]SELECT * FROM banlist WHERE username LIKE '%$username%'[/sql]
Reply With Quote
  #7  
Old 03-07-2008, 06:16 AM
Iskib Iskib is offline
 
Join Date: May 2006
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey still not working

Here is what I have full code..

Code:
require_once ('js/xajax_core/xajax.inc.php');
$xajax = new xajax();
$xajax->registerFunction("processForm");

function processForm($username)
{
    $ban_username_exists = sql_query("SELECT * FROM banned_usernames WHERE banned_username = '" .
        $username . "'");
    $result = sql_query(sprintf("SELECT * FROM users WHERE username = '%s'", $username));
    $banned = sql_query("SELECT * FROM usernames WHERE banned_username = '" . $username .
        "' LIKE '" . $username % "'");

    $objResponse = new xajaxResponse();
    if (empty($username)) {
        $objResponse->assign("result", "innerHTML",
            '<span style="color:#f00"><font size="2">Username Empty</font></span>');
    } elseif (!preg_match("/^[a-zA-Z\d\-_]+$/i", $username)) {
        $objResponse->assign("result", "innerHTML",
            '<span style="color:#f00"><font size="2">Invalid Username - Invalid Character or Space</font></span>');
    } elseif (mysql_num_rows($ban_username_exists) != '0') {
        $objResponse->assign("result", "innerHTML",
            '<span style="color:#f00"><font size="2">Invalid Username - Banned Username</font></span>');
    } elseif (mysql_fetch_row($banned)) {
        $objResponse->assign("result", "innerHTML",
            '<span style="color:#f00"><font size="2">Invalid Username - Banned Username</font></span>');
    } elseif (mysql_num_rows($result) > 0) {
        $objResponse->assign("result", "innerHTML",
            '<span style="color:#f00"><font size="2">Not Available</font></span>');
    } else {
        $objResponse->assign("result", "innerHTML",
            '<span style="color:#0c0"><font size="2">Available</font></span>');
    }
    return $objResponse;
}
$xajax->processRequest();
--------------- Added [DATE]1204900783[/DATE] at [TIME]1204900783[/TIME] ---------------

Other then the mySQL wildcard is there anyway of matching any username that would have part of a banned username? maybe a reg expression ?
Reply With Quote
  #8  
Old 03-07-2008, 01:42 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Does AdminCP > vBulletin Options > vBulletin Options > User Registration Options > Illegal User Names not cover what you want to do?
Reply With Quote
  #9  
Old 03-07-2008, 04:47 PM
Iskib Iskib is offline
 
Join Date: May 2006
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No. As I said in the third post in this thread. It is not a vbulletin site therefore the vbulletin option can not be used.

I am just asking for a little help
Reply With Quote
  #10  
Old 03-07-2008, 05:12 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Iskib View Post
No. As I said in the third post in this thread. It is not a vbulletin site therefore the vbulletin option can not be used.
Ah right must have missed that post.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:08 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05517 seconds
  • Memory Usage 2,250KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete