• [MOD] Ajax Username Checker 4 0 5 1
Currently:  

Author Topic: [MOD] Ajax Username Checker  (Read 43973 times)

0 Members and 1 Guest are viewing this topic.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
[MOD] Ajax Username Checker
« on: January 13, 2009, 01:07:58 PM »
Quote from original mod:
In this post,I’ll show you how to make a fancy username availability checking in ajax and php using jquery.When, you check the the username avaiability a fancy message box will show you the message with a little bit of animation. If you are looking for such kind of effect for checking username availability, then this might be right post for you.
http://roshanbh.com.np/2008/04/check-username-available-ajax-php-jquery.html

Download jquery.js file and upload it to root directory: (EDIT: I have attached file jquery.js to this message)
http://docs.jquery.com/Downloading_jQuery#Download_jQuery

Find in page_header.php
Code: [Select]
  "url_search" => $site_sess->url(ROOT_PATH."search.php"),
and add before:
Code: [Select]
  "url_user_availability" => $site_sess->url(ROOT_PATH."user_availability.php", "&"),
Open header.html
After:
Code: [Select]
<link rel="stylesheet" href="{template_url}/style.css" />
Add:
Code: [Select]
<script src="jquery.js" type="text/javascript" language="javascript"></script>

Open register_form.html
Add to the top:
Code: [Select]
<script language="javascript">
//<!---------------------------------+
//  Developed by Roshan Bhattarai
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use
// --------------------------------->
$(document).ready(function()
{
$("#username").blur(function()
{
//remove all the class add the messagebox classes and start fading
$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
//check the username exists or not from ajax
$.post("{url_user_availability}",{ user_name:$(this).val() } ,function(data)
        {
  if(data=='no') //if username not avaiable
  {
  $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
  //add message and change the class of the box and start fading
  $(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
});
          }
  else
  {
  $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
{
  //add message and change the class of the box and start fading
  $(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
});
  }

        });
 
});
});
</script>

Replace:
Code: [Select]
<input type="text" name="user_name" size="30" value="{user_name}" class="input" />
With:
Code: [Select]
<input type="text" name="user_name" size="30" value="{user_name}" id="username" class="input" /><span id="msgbox" style="display:none"></span>
Create new PHP file, name it user_availability.php and upload it to root directory:

Code: [Select]
<?php
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use

define('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');

if (isset(
$HTTP_POST_VARS['user_name'])) {
$user_name preg_replace("/[ ]{2,}/"" "un_htmlspecialchars(trim($HTTP_POST_VARS['user_name'])));

if ($user_name != "") {
  $sql "SELECT ".get_user_table_field("""user_name")."
  FROM "
.USERS_TABLE."
  WHERE "
.get_user_table_field("""user_name")." = '".strtolower($user_name)."'";
  if ($site_db->not_empty($sql)) {
//user name is not availble
echo "no";
  } else {
//user name is available
echo "yes";   
}
}
}
?>


Open style.css (folder: /templates/default) add to the end:
Code: [Select]
.messagebox{
position:absolute;
width:100px;
margin-left:10px;
padding:2px;
}
.messageboxok{
position:absolute;
width:auto;
margin-left:10px;
padding:2px;
font-weight:bold;
color:#008000;

}
.messageboxerror{
position:absolute;
width:auto;
margin-left:10px;
padding:2px;
font-weight:bold;
color:#CC0000;
}
« Last Edit: January 14, 2009, 09:07:24 AM by Lucifix »

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Re: [MOD] Ajax Username Checker
« Reply #1 on: January 13, 2009, 05:12:06 PM »
Nice, just make sure you use $site_sess->url() to generate the url to user_availability.php, otherwise it might create a new session (and slow down the script) on each request.
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [MOD] Ajax Username Checker
« Reply #2 on: January 13, 2009, 06:18:21 PM »
Thank you :)

But how would you use $site_sess->url() in javascript to generate that url?
« Last Edit: January 13, 2009, 07:31:38 PM by Lucifix »

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [MOD] Ajax Username Checker
« Reply #3 on: January 13, 2009, 07:31:56 PM »
Gosh, how can I forgot something like that  :roll: I'll post modification tomorrow. :wink:

Bye!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Ajax Username Checker
« Reply #4 on: January 14, 2009, 03:15:48 AM »
Also, <style> should be in header.html ;)
By the way, coincidentally, just a few days ago I had question regarding <style> myself
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [MOD] Ajax Username Checker
« Reply #5 on: January 14, 2009, 07:58:06 AM »
Also, <style> should be in header.html ;)

I have included <style> now directly in style.css file.

I hope this mod is valid now ;)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Ajax Username Checker
« Reply #6 on: January 14, 2009, 08:56:13 AM »
Since the URL is executed directly by JS, I think you should use $site_sess->url(ROOT_PATH."user_availability.php", "&")
otherwise you'll get url with &amp;

P.S.

Code: [Select]
  $user_name = (isset($HTTP_POST_VARS['user_name'])) ? un_htmlspecialchars(trim($HTTP_POST_VARS['user_name'])) : "";
  $user_name = ereg_replace("( ){2,}", " ", $user_name);

  if (isset($HTTP_POST_VARS['user_name'])) {

can be optimized with:
Code: [Select]
  if (isset($HTTP_POST_VARS['user_name'])) {
  $user_name = preg_replace("/[ ]{2,}/", " ", un_htmlspecialchars(trim($HTTP_POST_VARS['user_name'])));

I don't know why ereg_replace() exists, in my benchmark it's over 50% slower then preg_replace()
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [MOD] Ajax Username Checker
« Reply #7 on: January 14, 2009, 09:05:56 AM »
Thx, I fixed that!

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: [MOD] Ajax Username Checker
« Reply #8 on: March 19, 2009, 11:31:53 AM »
[MOD] Ajax Username Checker

Can this feature be extended for image verification and check email format too?

Thanks for this lovely MOD!

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [MOD] Ajax Username Checker
« Reply #9 on: March 19, 2009, 11:36:23 AM »
For image verification  defenitly not! But for email... maybe yes :roll:

Offline neverkas

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
    • FullPosteo
Re: [MOD] Ajax Username Checker
« Reply #10 on: May 25, 2009, 03:38:04 PM »
a mi no me funciona!  8O

Me dice que esta disponible tal usuario, pero en realidad ya está registrado...

Qué sucede? Por qué el error?
Hice paso por paso tal cual.
http://www.fullposteo.com.ar/



La nueva forma de compartir tus fotos y vídeos con tus amigos!

The new form to share photos and videos width your friends!

Offline Benny Change

  • Addicted member
  • ******
  • Posts: 1.788
  • #WWG1WGA
    • View Profile
    • Qlobal-Change
Re: [MOD] Ajax Username Checker
« Reply #11 on: May 28, 2009, 12:04:18 AM »
Kann das jemand vielleicht mal auffrischen?
In der 1.7.7 klappt das irgendwie nicht, obwohl ich mir nicht vorstellen kann warum.
Liegt es vielleicht an dieser PHP Datei, die man erstellen muss?

Ich würde gerne das Script verwenden:
http://www.pa-s.de/php/codeschnipsel-AJAX-Username-Check-52.php

Aber ich weis nicht wie man eine Datenbankanfrage erstellt!
« Last Edit: May 28, 2009, 01:00:46 AM by Benny »
Beste Grüße
Benny

Offline bergblume

  • Sr. Member
  • ****
  • Posts: 463
  • on to the top!
    • View Profile
Re: [MOD] Ajax Username Checker
« Reply #12 on: May 28, 2009, 08:59:31 AM »
kann man diesen mod mittlerweile auch als image name checker modifizieren und verwenden - sprich, dass wenn ein user z.B. "schönes Bild" als Bildname eingibt - dies automatisch gegengeprüft wird?

Offline Benny Change

  • Addicted member
  • ******
  • Posts: 1.788
  • #WWG1WGA
    • View Profile
    • Qlobal-Change
Re: [MOD] Ajax Username Checker
« Reply #13 on: May 28, 2009, 02:52:58 PM »
Die Idee finde ich ebenfalls sehr klasse!
Beste Grüße
Benny

Offline bergblume

  • Sr. Member
  • ****
  • Posts: 463
  • on to the top!
    • View Profile
Re: [MOD] Ajax Username Checker
« Reply #14 on: September 07, 2009, 05:23:25 PM »
gibt es hierzu evtl. schon was neues?

 

Post your comments here