zoukankan      html  css  js  c++  java
  • php注册登录源代码

    php注册登录源代码


    链接数据库

    <?php
    $conn=mysql_connect('localhost','root','');
    mysql_select_db('ht',$conn);
    mysql_query("set names utf8");
    error_reporting(0);
    ?>
    

      


    以下为注册源代码

    <?php
    
    //html POST 的数据
    $user1=$_POST['username1'];
    $password1=$_POST['password1'];
    //判断点击事件
    if(add==$_GET['add']){
    if( empty($user1) || empty($password1)){
    echo "<script>alert('必填处不能为空');window.location.href='denglu.php';</script>";
    }else{
    $sqlzc="insert into admin(id,username,password,name,sex)values('','$user1','$password1','','')";//添加数据库信息
    $row=mysql_query($sqlzc);
    if($row){
    echo "<script>alert('注册成功');window.location.href='index.php'</script>";
    }else{
    echo "<script>alert('注册失败');window.location.href='denglu.php'</script>";
    }
    }
    
    }
    ?>
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>注册</title>
    </head>
    <body>
    <form name="login" action="?add=add" method="post">
    <p>用户名<input type=text name="username1"></p>
    <p>密 码<input type=password name="password1"></p>
    <p><input type="submit" name="submit" value="注册"></p>
    </form>
    </body>
    </html>


    以下为登录源代码

    <?php
    //html POST 的数据
    $user=$_POST['name'];
    $password=$_POST['password'];
    //判断点击事件
    if(aee==$_GET['aee']){
    if( empty($user) || empty($password)){
    echo "<script>alert('必填处不能为空');window.location.href='denglu.php';</script>";
    }else{
    $sqlcx="select * from admin where username='$user' and password='$password' ";//检测数据库是否有对应username和password;
    $result = mysql_query($sqlcx);//执行sql
    $rows=mysql_num_rows($result);//返回一个数值
    if($rows){
    echo "<script>alert('登录成功');window.location.href='index.php'</script>";
    }else{
    echo "<script>alert('登录失败');window.location.href='denglu.php'</script>";
    }
    }
    
    }
    ?>
    
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>登陆</title>
    </head>
    <body>
    <form name="login" action="?aee=aee" method="post">
    <p>用户名<input type=text name="name"></p>
    <p>密 码<input type=password name="password"></p>
    <p><input type="submit" name="submit" value="登录"></p>
    </form>
    </body>
    </html>
    

    以下为PDO写法实例:

    <?php
    include "conn.php";  //链接数据库 
    header("Content-Type:text/html;charset=utf-8");
    unset($_SESSION["user"]);
    //html POST 的数据
    $user=$_POST['username'];
    $password=$_POST['password'];
    //判断点击事件
    
    if(aee==$_GET['aee']){  //登录判断php
    if( empty($user) || empty($password)){
    echo "<script>alert('必填处不能为空');window.location.href='login.php';</script>";
    }else{
    
    $sql = $db->query("SELECT * FROM users WHERE username='".$user."' AND password='".$password."'")->fetchAll(PDO::FETCH_ASSOC);
    
    if(count($sql) > 0){
         $_SESSION["user"]="yes";
    echo "<script>alert('登录成功');window.location.href='index.php'</script>";
    }else{
    echo "<script>alert('登录失败!');window.location.href='login.php'</script>";
    }
    }
    
    }
    if(reg==$_GET['reg']){ //注册判断php if( empty($user) || empty($password)){ exit("<script>alert('必填处不能为空');window.location.href='login.php';</script>"); } else if(!preg_match("/^d*$/",$user) && !preg_match("/^d*$/",$password)){ exit('<script>alert("账号与密码请填写数字");window.location.href="index.php";</script>'); } else if(strlen($user) < 6 && strlen($password) < 6){ exit("<script>alert('账号与密码长度不能少于6位数');window.location.href='login.php';</script>"); } else{ $sql = $db->query("SELECT * FROM users WHERE username='".$user."'")->fetchAll(PDO::FETCH_ASSOC); if(count($sql) > 0){ exit('<script>alert("该账号已被注册");window.location.href="index.php";</script>'); } $sql = $db->query("INSERT INTO users (id,username,password) VALUES ('','".$user."','".$password."')"); if($sql > 0){ echo "<script>alert('注册成功');window.location.href='index.php'</script>"; }else{ echo "<script>alert('注册失败');window.location.href='login.php'</script>"; } } } //echo "<script>alert('".$user.'<br>'.$password.count($sql)."')</script>"; ?>
  • 相关阅读:
    我用纯C语言开发的中英文混合分词服务器3.0正式发布,词库190多万词,每秒切分5万+,同时提供 c、java、C#、delphi、js调用范例
    藏拙空间上线了!
    说实话我只能灌水,我谈技术你们有几个懂的啊?不信?随便发一段我写的代你们有几个能看懂的啊?
    明明三句话就能说清楚的事,专家们长篇大论,为何?
    正在开发云ERP,业务功能与天心CS ERP一模一样, 欢迎大家指正
    我的 云寻觅 搜索引擎 开始公测,前天开始开发,昨天买域名,今天发布在本机,请各路专家指正! 顺便开源!
    20071225是个值得纪念的日子,我用纯C语言开发的空间首次上线测试!
    给C# .NET 的兄弟们做点小贡献 NoSql LevelDB .net 移植版 普通PC 100万条数据插入不超过4秒
    开源:给每个文档计算一个指纹,然后用指纹进行相似度的计算 含源码和可执行程序
    国内首款完全由国人自主研发的开源云平台 BDC3.0 详解
  • 原文地址:https://www.cnblogs.com/fan-bk/p/6937740.html
Copyright © 2011-2022 走看看