当前位置:   article > 正文

PHP-用户登录注册接口_php用户账号密码登录的接口

php用户账号密码登录的接口

新版本的PHP中mysql_conntent()【regcheck.php】等函数改成了mysqli_conntent()【logincheck.php】,参数也有所变化。但不影响正常使用。出现警告时用函数

error_reporting(0)隐藏警告

登录-login.php:

  1. <form action="logincheck.php" method="post">
  2. 用户名:<input type="text" name="username" />
  3. <br />
  4. 密码:<input type="password" name="password" />
  5. <br />
  6. <input type="Submit" name="Submit" value="登陆" />
  7. <a href="register.php">注册</a>
  8. </form>
登录检测-logcheck.php:

  1. <?php
  2. if(isset($_POST["Submit"]) && $_POST["Submit"] == "登陆")
  3. {
  4. $user = $_POST["username"];
  5. $psw = $_POST["password"];
  6. if($user == "" || $psw == "")
  7. {
  8. echo "<script>alert('请输入用户名或密码!'); history.go(-1);</script>";
  9. }
  10. else
  11. {
  12. $con = mysqli_connect("localhost","root","root");
  13. mysqli_select_db($con ,"vt");
  14. mysqli_query($con,"set names 'gbk'");
  15. $sql = "select username,password from user where username = '$_POST[username]' and password = '$_POST[password]'";
  16. $result = mysqli_query($con ,$sql);
  17. $num = mysqli_num_rows($result);
  18. if($num)
  19. {
  20. $row = mysqli_fetch_array($result,MYSQLI_NUM); //将数据以索引方式储存在数组中
  21. echo $row[0];
  22. }
  23. else
  24. {
  25. echo "<script>alert('用户名或密码不正确!');history.go(-1);</script>";
  26. }
  27. }
  28. }
  29. else
  30. {
  31. echo "<script>alert('提交未成功!'); history.go(-1);</script>";
  32. }
  33. ?>

注册-register.php:

  1. <form action="regcheck.php" method="post">  
  2.     用户名:<input type="text" name="username"/>  
  3.     <br/>  
  4.     密 码:<input type="password" name="password"/>  
  5.     <br/>  
  6.     确认密码:<input type="password" name="confirm"/>  
  7.     <br/>  
  8.     <input type="Submit" name="Submit" value="注册"/>  
  9. </form>

注册检测-regcheck.php:

  1. <?php
  2. error_reporting(0);
  3. if(isset($_POST["Submit"]) && $_POST["Submit"] == "注册")
  4. {
  5. $user = $_POST["username"];
  6. $psw = $_POST["password"];
  7. $psw_confirm = $_POST["confirm"];
  8. if($user == "" || $psw == "" || $psw_confirm == "")
  9. {
  10. echo "<script>alert('请确认信息完整性!'); history.go(-1);</script>";
  11. }
  12. else
  13. {
  14. if($psw == $psw_confirm)
  15. {
  16. mysql_connect("localhost","root","root"); //连接数据库
  17. mysql_select_db("vt"); //选择数据库
  18. mysql_query("set names 'gdk'"); //设定字符集
  19. $sql = "select username from user where username = '$_POST[username]'"; //SQL语句
  20. $result = mysql_query($sql); //执行SQL语句
  21. $num = mysql_num_rows($result); //统计执行结果影响的行数
  22. if($num) //如果已经存在该用户
  23. {
  24. echo "<script>alert('用户名已存在'); history.go(-1);</script>";
  25. }
  26. else //不存在当前注册用户名称
  27. {
  28. $sql_insert = "insert into user (username,password,phone,address) values('$_POST[username]','$_POST[password]','','')";
  29. $res_insert = mysql_query($sql_insert);
  30. //$num_insert = mysql_num_rows($res_insert);
  31. if($res_insert)
  32. {
  33. echo "<script>alert('注册成功!'); history.go(-1);</script>";
  34. }
  35. else
  36. {
  37. echo "<script>alert('系统繁忙,请稍候!'); history.go(-1);</script>";
  38. }
  39. }
  40. }
  41. else
  42. {
  43. echo "<script>alert('密码不一致!'); history.go(-1);</script>";
  44. }
  45. }
  46. }
  47. else
  48. {
  49. echo "<script>alert('提交未成功!'); history.go(-1);</script>";
  50. }
  51. ?>


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/270154?site
推荐阅读
相关标签
  

闽ICP备14008679号