search
Homephp教程php手册php ajax用户登录代码

php ajax用户登录代码

Jun 13, 2016 am 10:03 AM
ajaxphponecodegetting StartedbeginnerCanhaveuserLog inof

一款入门级的ajax用户登录代码,有需要的初学者可以参考一下,

login.html

 代码如下 复制代码
用户名
密码

js代码

 代码如下 复制代码

function chk_login(form){
    var username=form.username;
    var password=form.password;
    if(username.value == ""){
        alert("用户名不能为空");
        username.focus();
        return false;
    }
    if(password.value == ""){
        alert("密码不能为空");
        password.focus();
        return false;
    }

    var url = 'login_chk.php?username='+username.value+'&password='+password.value;
    xmlhttp.open('get',url,true);
//为什么下面加了下面注释掉的代码后,会没反应了,没加就有反应,我的php文件路径都是正确的,也有引入xmlhttprequest.js
xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4){
            if(xmlhttp.status == 200){
                var msg = xmlhttp.responseText;
                if(msg == "1"){
                    alert("登陆成功");
                    window.location='index.php?name='+username.value;
                }else if((msg == "2"){
                    alert("登陆用户名或密码错误");
                }else{
                    alert(msg);
                }
            }
        }
    }
    xmlhttp.send(null);*/
}

ogin

_chk.php

 代码如下 复制代码

echo 1
?>

因为是测试文件所以没读取数据库了,这里就不写了有需要的朋友可以自己加上读数据库用户名记录,如果存在就返回1就可以了。

有关教程可以参考

http://www.bKjia.c0m/phper/php-cy/34654.htm

http://www.bKjia.c0m/phper/21/46169c59dabdf0501de3d9ac9653e096.htm

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools