Total members 9936 | Gratitudes |It is currently Sun Feb 05, 2012 8:03 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: login using Ajax
PostPosted: Fri Dec 26, 2008 1:43 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2101
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

Hi, i have created a code to login using ajax , the code is so easy , here i have two files , one contain the ajax code with a form to login and other file contain the check on the username and password .
Here is the first file Ajaxlogin.php :
Code:
<html>
<
head>
<
script language="javascript">
function 
postRequest(strURL){
var 
xmlHttp;
if(
window.XMLHttpRequest){ // For Mozilla, Safari, ...
var xmlHttp = new XMLHttpRequest();
}
else if(
window.ActiveXObject){ // For Internet Explorer
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.open('POST'strURLtrue);
xmlHttp.setRequestHeader('Content-Type''application/x-www-form-urlencoded');
xmlHttp.onreadystatechange = function(){
if (
xmlHttp.readyState == 4){
ajaxloginupdate(xmlHttp.responseText);
}
}
xmlHttp.send(strURL);
}

function 
ajaxloginupdate(str){
if(
str=="ok"){
alert("Hi , user");
}else{
alert("Login falied try again later");
}
}

function 
loginajax(){
var 
username window.document.loginform.username.value;
var 
password window.document.loginform.password.value;
var 
url "login.php?username=" username "&password=" +password ;
postRequest(url);

</script>
</head>

<body>
<Center>

<form name="loginform" onsubmit="return loginajax();">
<table border="0" bgcolor="#00CC66" cellspacing="1" cellpadding="3" width="300">
<tr>
<td align="left" colspan="2" width="300"><b><font size="5" color="#990000">Login Form</font></b></td>
</tr>
<tr>
<td align="right" width="90"><b><font color="#0000CC">Username:</font></b></td>
<td width="175"><input type="text" name="username" id="user" size="30" value="" /></td>
</tr>
<tr>
<td align="right" width="90"><b><font color="#0000CC">Password:</font></b></td>
<td width="175"><input type="password" name="password" size="30" value="" /></td>
</tr>
<tr>
<td colspan="2" align="center" width="275"><input type="button" name="LoginButton" value="Login" onclick="loginajax()"></td>
</tr>
</table>
</form>

</center>
</body>
</html>


Here the second file , you can make a check for the username and password in your database ,but for simplicity i just make a check for a certain username and password .

Code:

<?
$username
=$_GET["username"];
$password=$_GET["password"];
if(
$username=="root" && $password=="root"){
echo 
"ok";
}else{
echo 
"fail";
}
?>

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 login using jsp  JSP Examples  msi_333  10
 Ajax Source code to Suggest application with JSP Server side  AJAX  msi_333  5
 [Ajax/PHP] Registration - Check for empty textboxs  AJAX  PF2G  0
 php login form (sign-in form)  PHP examples  msi_333  0
 login using sessionid or time  PHP  ravi951  5

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team