php實(shí)現(xiàn)用戶注冊(cè)密碼的crypt加密
本文實(shí)例為大家分享了php用戶注冊(cè)密碼的加密,供大家參考,具體內(nèi)容如下
一、代碼
1、conn.php
<?php $conn = mysql_connect("localhost", "root", "111") or die("連接數(shù)據(jù)庫服務(wù)器失敗!".mysql_error()); //連接MySQL服務(wù)器 mysql_select_db("db_database21",$conn); //選擇數(shù)據(jù)庫db_database21 mysql_query("set names utf8"); //設(shè)置數(shù)據(jù)庫編碼格式utf8 ?>
2、index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>用戶注冊(cè)</title> <style type="text/css"> <!-- body,td,th { font-size: 12px; } --> </style></head> <body> <form id="form1" name="form1" method="post" action="index_ok.php"> <fieldset style="width:500px"><legend style="font-size:16px">用戶注冊(cè)</legend><table width="300" border="0" align="center"> <tr> <td width="77" align="right">用戶名:</td> <td width="213"><input name="user" type="text" id="user" size="24" /></td> </tr> <tr> <td align="right">密碼:</td> <td><input name="pwd" type="password" id="pwd" size="25" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="sub" value="注冊(cè)" /> <input type="reset" name="res" value="重置" /></td> </tr> </table></fieldset> </form> </body> </html>
3、index_ok.php
<?php header("content-type:text/html;charset=utf-8"); //加載頭信息 include("conn/conn.php");//包含數(shù)據(jù)庫連接文件 if(trim($_POST['user'])!= "" and trim($_POST['pwd'])!= ""){//判斷輸入是否為空 $pwd = crypt($_POST['pwd'],"key");//對(duì)輸入的密碼進(jìn)行crypt加密 $sql = "insert into tb_user(username,password)values('".$_POST[user]."','". $pwd."')";//定義sql語句 $result = mysql_query($sql,$conn);//執(zhí)行sql語句 if($result){ echo "<font color='red'>注冊(cè)成功。</font>";//如果結(jié)果為真提示注冊(cè)成功 }else{ echo "<font color='green'>注冊(cè)失敗!</font>";//否則提示注冊(cè)失敗 } }else{ echo "請(qǐng)認(rèn)真填寫用戶名和密碼!";//提示輸入用戶名和密碼 } ?>
二、運(yùn)行結(jié)果
注冊(cè)成功后,數(shù)據(jù)庫顯示如下:
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Ajax+Jpgraph實(shí)現(xiàn)的動(dòng)態(tài)折線圖功能示例
這篇文章主要介紹了Ajax+Jpgraph實(shí)現(xiàn)的動(dòng)態(tài)折線圖功能,結(jié)合實(shí)例形式分析了ajax結(jié)合jpgraph.php類庫繪制動(dòng)態(tài)折線圖的相關(guān)操作技巧,需要的朋友可以參考下2019-02-02騰訊微博提示missing parameter errorcode 102 錯(cuò)誤的解決方法
這篇文章主要介紹了騰訊微博提示missing parameter errorcode 102 錯(cuò)誤的解決方法,是針對(duì)騰訊微博接口開發(fā)中比較典型的錯(cuò)誤問題,需要的朋友可以參考下2014-12-12php使用socket調(diào)用http和smtp協(xié)議實(shí)例小結(jié)
這篇文章主要介紹了php使用socket調(diào)用http和smtp協(xié)議,結(jié)合實(shí)例形式總結(jié)分析了php使用socket發(fā)送http請(qǐng)求、post請(qǐng)求、SMTP請(qǐng)求、郵件發(fā)送等相關(guān)操作技巧,需要的朋友可以參考下2019-07-07mysql desc(DESCRIBE)命令實(shí)例講解
這篇文章主要介紹了mysql desc(DESCRIBE)命令實(shí)例講解的相關(guān)資料,需要的朋友可以參考下2016-09-09