生活随笔
收集整理的這篇文章主要介紹了
使用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]'";?????????????????$result?=?mysql_query($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);??????????????????????????????????????????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实现用户登录和注册的功能的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。