Wednesday, April 29, 2009

Check username availability in ajax and php using jquery’s

Now let’s check it how to do check the username avaiability in ajax and php using jQuery.

Html Code :


<div>
User Name : <input name="username" id="username" value="" maxlength="15" type="text">
<span id="msgbox" style="display: none;"></span>
</div>

As you can see the above the “span” with id “msgbox” will show you the username availability message from ajax.

Css code :

.messagebox{
position:absolute;
width:100px;
margin-left:30px;
border:1px solid #c93;
background:#ffc;
padding:3px;
}
.messageboxok{
position:absolute;
width:auto;
margin-left:30px;
border:1px solid #349534;
background:#C9FFCA;
padding:3px;
font-weight:bold;
color:#008000;
}
.messageboxerror{
position:absolute;
width:auto;
margin-left:30px;
border:1px solid #CC0000;
background:#F7CBCA;
padding:3px;
font-weight:bold;
color:#CC0000;
}

I’ve defined three different class for three type of different message class “messagebox” for “checking….” message, “messageboxok” and “messageboxerror” class for displaying username available and not available messages.

As you know you can change the attriubutes of the css of the above code but keep in mind that “position” property should be “absolute”.

Javascript code :

First of all, the jQuery library is used,

<script src="jquery.js" type="text/javascript" language="javascript"></script>

As you can see in the first line, “all” css class is removed from the div displaying the message and then “messagebox” class is added to that that element with adding the text “checking” within the element and displaying with fading effect.


$("#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("user_availability.php",{ 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);
});
}
});
});

After that, ajax is used to call the PHP file, and when response is received through Ajax then jQuery is used to show the respective message-box with fading effects.

Php Code:

//this varible contains the array of existing users
$existing_users=array('roshan','mike','jason');
//value got from the get metho
$user_name=$_POST['user_name'];
//checking weather user exists or not in $existing_users array
if (in_array($user_name, $existing_users))
{
//user name is not available
echo "no";
}
else
{
//username available i.e. user name doesn't exists in array
echo "yes";
}

In the above PHP code, I’ve added three usernames in a array and then check weather that user exists or not in that array and print “yes” or “no” accordingly. The response taken from ajax is used within JavaScript function to display the appropriate message.But, you can use database connection to check the the availability of username in your code.


View Live Demo
Download full source

Source : http://roshanbh.com.np/2008/04/check-username-available-ajax-php-jquery.html

Read More...

Sunday, December 21, 2008

PHP > Sample Class Login with secure session

This class can be used to prevent security attacks known as session hijacking and session fixation.

When a session is initialized the class computes a fingerprint string that takes in account the browser user agent string, the user agent IP address or part of it and a secret word. If the fingerprint value changes, it is very likely that the session was hijacked and it should no longer be accepted.

To prevent session fixation attacks the calls the PHP session_regenerate_id() function so the session identifier changes everytime the session is checked.

Download : secureSession.zip [ mirror ]

Reference : www.phpclasses.org

Read More...

PHP > Sample Guest Book With Spam Filter

This class can automatically classify text messages to determine whether or not their are considered to be spam.

It can build a knowledge base of known text expressions that can be looked up later to evaluate a factor that expresses the probability of a given text to be spam.

This class could be used in Web mail applications or even in less obvious applications like forums and guest books, acting like an semi-automatic moderator.

Download : SpamFilter.zip [ mirror ]

Other Popular Guestbooks
This method takes all of the POST content, creates a single string, and runs it through SLV. It also removes your host name from the input in case you are passing on a variable such as a thank you page. I have implemented it on several popular guestbooks. I have not tested the code though, it may need some tweaks.

Reference :
- www.phpclasses.org
- www.linksleeve.org

Read More...

Sample 3D Programming With VB

If you want to take part in one of the most incredible computer gaming experiences available, Genesis Entertainment L.C. is currently working on Realms of Time, a state-of-the-art RPG designed to revolutionize the gaming world. If you or anyone you know has experience in C++ or excellent skills in VB graphic or text programming, or if you just want to hear the details of this incredible project, contact me at the e-mail address listed below. Beta testers will be needed at some point in the future (NOT NOW, though, so don't ask for now!), so if you want to be on the list of candidates, contact me with a PROFESSIONAL resume detailing your experience.

Also, and most importantly, we are looking for a talented 3D Graphics designer to help us with the many characters, both human and non-human, that will be needed for our game. We are currently working on producing our own, but because our immediate focus is on scripting out the details of the storyline and building peripheral programs (like the map, magic, item, and character editors), we don't have a lot of time to spend on our graphics. We are specifically looking for two types of 3D Graphics - characters (humans, monsters, etc.) that are similar to the style of Diablo characters (i.e. very nicely done at a small size, so huge amounts of close-up details aren't necessary), and 3D CG movies (we are aiming for CG graphics similar to those in Final Fantasy 7, and hopefully Final Fantasy 8, although those kind of graphics are most likely far out of our (or anyone but SquareSoft's) reach) with the same creatures mentioned above, except life-size and totally realistic. If you or anyone you know may be interested, contact the Realms of Time production team at realmsoftime@usa.net.

Download Sample with Source Code Here [ mirror ]

Read More...

How to empty Recycle bin with Delphi

Code :

Procedure EmptyRecycleBin ;
Const
SHERB_NOCONFIRMATION = $00000001 ;
SHERB_NOPROGRESSUI= $00000002 ;
SHERB_NOSOUND= $00000004 ;
Type
TSHEmptyRecycleBin = function (Wnd : HWND;
pszRootPath : PChar;
dwFlags : DWORD
) : HRESULT; stdcall ;
Var
SHEmptyRecycleBin : TSHEmptyRecycleBin;
LibHandle : THandle;
Begin
LibHandle := LoadLibrary(PChar('Shell32.dll')) ;
if LibHandle <> 0 then
@SHEmptyRecycleBin := GetProcAddress(LibHandle, 'SHEmptyRecycleBinA')
else
begin
MessageBox(GetActiveWindow,PChar('Gagal melakukan loading Shell32.dll.'),'Error',24);
Exit;
end;
if @SHEmptyRecycleBin <> nil then
SHEmptyRecycleBin(GetActiveWindow,
nil,
SHERB_NOCONFIRMATION or SHERB_NOPROGRESSUI or SHERB_NOSOUND);
FreeLibrary(LibHandle);
@SHEmptyRecycleBin := nil ;
end;

Read More...

Delphi > Procedure Disable Ctrl Alt Del

procedure DisableCtrlAltDel(BDisable:Boolean);
const
VAL_DisableTaskMgr='DisableTaskMgr';
var
MyW: Word;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
Begin
with Tregistry.Create do try
RootKey:=HKEY_CURRENT_USER;
OpenKey(RegSystemKey,TRUE);
IF Bdisable=true then
WriteInteger(VAL_DisableTaskMgr,1)
else
DeleteValue(VAL_DisableTaskMgr);
CloseKey;
finally
Free;
end;
end
else
begin
// hanya untuk windows 95 / NT 4.0
if BDisable then
begin
{Disable ALT-TAB}
SystemParametersInfo( SPI_SETFASTTASKSWITCH, 1, @Myw, 0);
{Disable CTRL-ALT-DEL}
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @Myw, 0);
end
else
begin
{Enable ALT-TAB}
SystemParametersInfo( SPI_SETFASTTASKSWITCH, 0, @Myw, 0);
{Enable CTRL-ALT-DEL}
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 0, @Myw, 0);
end;
end;
end;

Read More...

Friday, December 5, 2008

VB > Function Disconnect from the internet


Public Const RAS_MAXENTRYNAME As Integer = 256
Public Const RAS_MAXDEVICETYPE As Integer = 16
Public Const RAS_MAXDEVICENAME As Integer = 128
Public Const RAS_RASCONNSIZE As Integer = 412

Public Type RasEntryName
dwSize As Long
szEntryName(RAS_MAXENTRYNAME) As Byte
End Type

Public Type RasConn
dwSize As Long
hRasConn As Long
szEntryName(RAS_MAXENTRYNAME) As Byte
szDeviceType(RAS_MAXDEVICETYPE) As Byte
szDeviceName(RAS_MAXDEVICENAME) As Byte
End Type

Public Declare Function RasEnumConnections Lib _
"rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasConn As _
Any, lpcb As Long, lpcConnections As Long) As Long

Public Declare Function RasHangUp Lib "rasapi32.dll" Alias _
"RasHangUpA" (ByVal hRasConn As Long) As Long

Public gstrISPName As String
Public ReturnCode As Long

Public Sub HangUp()
Dim i As Long
Dim lpRasConn(255) As RasConn
Dim lpcb As Long
Dim lpcConnections As Long
Dim hRasConn As Long
lpRasConn(0).dwSize = RAS_RASCONNSIZE
lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
lpcConnections = 0
ReturnCode = RasEnumConnections(lpRasConn(0), lpcb, _
lpcConnections)

If ReturnCode = ERROR_SUCCESS Then
For i = 0 To lpcConnections - 1
If Trim(ByteToString(lpRasConn(i).szEntryName)) _
= Trim(gstrISPName) Then
hRasConn = lpRasConn(i).hRasConn
ReturnCode = RasHangUp(ByVal hRasConn)
End If
Next i
End If

End Sub

Public Function ByteToString(bytString() As Byte) As String
Dim i As Integer
ByteToString = ""
i = 0
While bytString(i) = 0&
ByteToString = ByteToString & Chr(bytString(i))
i = i + 1
Wend
End Function

Read More...

Latest Comments

About Me

My Photo
Makassar, Sulawesi Selatan, Indonesia
View my complete profile

Guest Book


ShoutMix chat widget

Script Sense ©Template Blogger Green by Dicas Blogger.

TOPO