Total members 11797 |It is currently Fri Sep 20, 2019 12:26 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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";
}
?>





Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : login using Ajax
 Ajax Login     -  
 code for login by jsp and ajax     -  
 AJAX Login Code getting username and password dynamically .     -  
 develop a login page- login servlet - ServletContext     -  
 What is AJAX, How to start AJAX?     -  
 login using jsp     -  
 ASP.NET 2.0 Login Controls     -  
 php login with session     -  
 How to Show a message before the login ?     -  
 Cookie based login in php     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com