It is currently Fri Jul 30, 2010 1:54 pm


All times are UTC [ DST ]


Ask on Codemiles community and get answers Free and Fast :

AJAX codes,AJAX tricks ,AJAX faq ,AJAX answers .and more

Our guest share with us your code snippets , your programming problems , your open source projects ,read articles and post yours .







Post new topic Reply to topic  [ 1 post ] 
  Print view Previous topic | Next topic 
Author Message
 Post 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: 1573
Location: Earth
Has thanked: 10 time
Have thanks: 16 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 .


TOP
 Profile Send private message  
 
| More
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


 Similar topics
 Topic title   Forum   Author   Replies 
 How to Show a message before the login ?  PHPbb3 support  Max300  1
 Struts2 upload file and ajax  Servlets / JSP  AskBot  2
 software engineer/ Asp.net/AJAX/VB,net/C#.  Job Opportunities  AiryConsulting2010  0
 Solution to AJax Cache problem with Internet Explorer  AJAX  msi_333  3
 AJAX form validation  AJAX  gilbertsavier  0

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  





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-2009
mileX v1.0 designed by codemiles team