日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

使用PHP实现用户登录和注册的功能

發布時間:2024/4/17 php 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用PHP实现用户登录和注册的功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

登陸界面 login.PHP

?

[html]?view plaincopy
  • <form?action="logincheck.php"?method="post">??
  • ????用戶名:<input?type="text"?name="username"?/>??
  • ????<br?/>??
  • ????密碼:<input?type="password"?name="password"?/>??
  • ????<br?/>??
  • ????<input?type="submit"?name="submit"?value="登陸"?/>??
  • ??????????
  • ????<a?href="register.php">注冊</a>??
  • </form>??
  • 登錄處理界面 logincheck.php

    ?

    ?

    [php]?view plaincopy
  • <?php??
  • ????if(isset($_POST["submit"])?&&?$_POST["submit"]?==?"登陸")??
  • ????{??
  • ????????$user?=?$_POST["username"];??
  • ????????$psw?=?$_POST["password"];??
  • ????????if($user?==?""?||?$psw?==?"")??
  • ????????{??
  • ????????????echo?"<script>alert('請輸入用戶名或密碼!');?history.go(-1);</script>";??
  • ????????}??
  • ????????else??
  • ????????{??
  • ????????????mysql_connect("localhost","root","sixx");??
  • ????????????mysql_select_db("vt");??
  • ????????????mysql_query("set?names?'gbk'");??
  • ????????????$sql?=?"select?username,password?from?user?where?username?=?'$_POST[username]'?and?password?=?'$_POST[password]'";??
  • ????????????$result?=?mysql_query($sql);??
  • ????????????$num?=?mysql_num_rows($result);??
  • ????????????if($num)??
  • ????????????{??
  • ????????????????$row?=?mysql_fetch_array($result);??//將數據以索引方式儲存在數組中??
  • ????????????????echo?$row[0];??
  • ????????????}??
  • ????????????else??
  • ????????????{??
  • ????????????????echo?"<script>alert('用戶名或密碼不正確!');history.go(-1);</script>";??
  • ????????????}??
  • ????????}??
  • ????}??
  • ????else??
  • ????{??
  • ????????echo?"<script>alert('提交未成功!');?history.go(-1);</script>";??
  • ????}??
  • ??
  • ?>??
  • 注冊界面 register.php

    ?

    ?

    [html]?view plaincopy
  • <form?action="regcheck.php"?method="post">??
  • ????用戶名:<input?type="text"?name="username"/>??
  • ????<br/>??
  • ????密 碼:<input?type="password"?name="password"/>??
  • ????<br/>??
  • ????確認密碼:<input?type="password"?name="confirm"/>??
  • ????<br/>??
  • ????<input?type="Submit"?name="Submit"?value="注冊"/>??
  • </form>??
  • 注冊處理界面 regcheck.php

    ?

    ?

    [php]?view plaincopy
  • <?php??
  • ????if(isset($_POST["Submit"])?&&?$_POST["Submit"]?==?"注冊")??
  • ????{??
  • ????????$user?=?$_POST["username"];??
  • ????????$psw?=?$_POST["password"];??
  • ????????$psw_confirm?=?$_POST["confirm"];??
  • ????????if($user?==?""?||?$psw?==?""?||?$psw_confirm?==?"")??
  • ????????{??
  • ????????????echo?"<script>alert('請確認信息完整性!');?history.go(-1);</script>";??
  • ????????}??
  • ????????else??
  • ????????{??
  • ????????????if($psw?==?$psw_confirm)??
  • ????????????{??
  • ????????????????mysql_connect("localhost","root","sixx");???//連接數據庫??
  • ????????????????mysql_select_db("vt");??//選擇數據庫??
  • ????????????????mysql_query("set?names?'gdk'");?//設定字符集??
  • ????????????????$sql?=?"select?username?from?user?where?username?=?'$_POST[username]'";?//SQL語句??
  • ????????????????$result?=?mysql_query($sql);????//執行SQL語句??
  • ????????????????$num?=?mysql_num_rows($result);?//統計執行結果影響的行數??
  • ????????????????if($num)????//如果已經存在該用戶??
  • ????????????????{??
  • ????????????????????echo?"<script>alert('用戶名已存在');?history.go(-1);</script>";??
  • ????????????????}??
  • ????????????????else????//不存在當前注冊用戶名稱??
  • ????????????????{??
  • ????????????????????$sql_insert?=?"insert?into?user?(username,password,phone,address)?values('$_POST[username]','$_POST[password]','','')";??
  • ????????????????????$res_insert?=?mysql_query($sql_insert);??
  • ????????????????????//$num_insert?=?mysql_num_rows($res_insert);??
  • ????????????????????if($res_insert)??
  • ????????????????????{??
  • ????????????????????????echo?"<script>alert('注冊成功!');?history.go(-1);</script>";??
  • ????????????????????}??
  • ????????????????????else??
  • ????????????????????{??
  • ????????????????????????echo?"<script>alert('系統繁忙,請稍候!');?history.go(-1);</script>";??
  • ????????????????????}??
  • ????????????????}??
  • ????????????}??
  • ????????????else??
  • ????????????{??
  • ????????????????echo?"<script>alert('密碼不一致!');?history.go(-1);</script>";??
  • ????????????}??
  • ????????}??
  • ????}??
  • ????else??
  • ????{??
  • ????????echo?"<script>alert('提交未成功!');?history.go(-1);</script>";??
  • ????}??
  • ?>??
  • 使用PHP實現用戶登錄和注冊功能——MySQL數據庫文件

    轉載于:https://www.cnblogs.com/suzmin/p/6809476.html

    總結

    以上是生活随笔為你收集整理的使用PHP实现用户登录和注册的功能的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。