欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php注冊登錄系統(tǒng)簡化版

 更新時間:2020年12月28日 14:25:07   作者:Leinov  
這篇文章主要為大家詳細介紹了php注冊登錄系統(tǒng)簡化版的實現(xiàn)步驟,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

登錄注冊系統(tǒng)是日常上網(wǎng)最普通的操作,我設了一個分類一步步完善注冊登錄系統(tǒng),若哪里有誤,請見諒。

所用語言:php

數(shù)據(jù)庫 :mysql

本次實現(xiàn)功能:

1.用戶注冊

2.用戶登錄

主要文件:

完整代碼

1 sql 在已有的數(shù)據(jù)庫里創(chuàng)建user表,id,username,password三個字段

復制代碼 代碼如下:
create table user(id int(10) not null auto_increment,username varchar(30),password varchar(40),primary key(id)); 

2 connect.php 數(shù)據(jù)庫配置文件

<?php
 $server="localhost";//主機
 $db_username="";//你的數(shù)據(jù)庫用戶名
 $db_password="";//你的數(shù)據(jù)庫密碼

 $con = mysql_connect($server,$db_username,$db_password);//鏈接數(shù)據(jù)庫
 if(!$con){
  die("can't connect".mysql_error());//如果鏈接失敗輸出錯誤
 }
 
 mysql_select_db('test',$con);//選擇數(shù)據(jù)庫(我的是test)
?>

3 signup.html 注冊表單

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>用戶注冊頁面</title>
 </head>
 <body>
  <form action="signup.php" method="post">
   <p>用戶名:<input type="text" name="name"></p>
   <p>密 碼: <input type="text" name="password"></p>
   <p><input type="submit" name="submit" value="注冊"></p>
  </form>
 </body>
</html>

 4 signup.php 注冊程序

<?php 
 header("Content-Type: text/html; charset=utf8");

 if(!isset($_POST['submit'])){
  exit("錯誤執(zhí)行");
 }//判斷是否有submit操作

 $name=$_POST['name'];//post獲取表單里的name
 $password=$_POST['password'];//post獲取表單里的password

 include('connect.php');//鏈接數(shù)據(jù)庫
 $q="insert into user(id,username,password) values (null,'$name','$password')";//向數(shù)據(jù)庫插入表單傳來的值的sql
 $reslut=mysql_query($q,$con);//執(zhí)行sql
 
 if (!$reslut){
  die('Error: ' . mysql_error());//如果sql執(zhí)行失敗輸出錯誤
 }else{
  echo "注冊成功";//成功輸出注冊成功
 }
 mysql_close($con);//關閉數(shù)據(jù)庫

?>

注冊流程完成,下面是用戶登錄

5 login.html 登錄表單

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>登陸</title>
 </head>
 <body>
  <form name="login" action="login.php" 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>

6 login.php 登錄程序

<?PHP
 header("Content-Type: text/html; charset=utf8");
 if(!isset($_POST["submit"])){
  exit("錯誤執(zhí)行");
 }//檢測是否有submit操作 

 include('connect.php');//鏈接數(shù)據(jù)庫
 $name = $_POST['name'];//post獲得用戶名表單值
 $passowrd = $_POST['password'];//post獲得用戶密碼單值

 if ($name && $passowrd){//如果用戶名和密碼都不為空
    $sql = "select * from user where username = '$name' and password='$passowrd'";//檢測數(shù)據(jù)庫是否有對應的username和password的sql
    $result = mysql_query($sql);//執(zhí)行sql
    $rows=mysql_num_rows($result);//返回一個數(shù)值
    if($rows){//0 false 1 true
     header("refresh:0;url=welcome.html");//如果成功跳轉(zhuǎn)至welcome.html頁面
     exit;
    }else{
    echo "用戶名或密碼錯誤";
    echo "
     <script>
       setTimeout(function(){window.location.href='login.html';},1000);
     </script>

    ";//如果錯誤使用js 1秒后跳轉(zhuǎn)到登錄頁面重試;
    }
    

 }else{//如果用戶名或密碼有空
    echo "表單填寫不完整";
    echo "
      <script>
       setTimeout(function(){window.location.href='login.html';},1000);
      </script>";

      //如果錯誤使用js 1秒后跳轉(zhuǎn)到登錄頁面重試;
 }

 mysql_close();//關閉數(shù)據(jù)庫
?>

7 welcome.html 登錄成功跳轉(zhuǎn)頁面

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>登陸成功</title>
 </head>
 <body>
  歡迎光臨
 </body>
</html>

至此一個簡單的完整的注冊登錄系統(tǒng)完成,代碼很簡單沒有考慮驗證安全性健壯性,之后在進行完善。

希望本文所述對大家學習php程序設計有所幫助。

相關文章

最新評論