溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

crypt加密如何在php項目中使用

發(fā)布時間:2020-12-09 16:04:51 來源:億速云 閱讀:163 作者:Leah 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)crypt加密如何在php項目中使用,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

一、代碼

1、conn.php

<&#63;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 
&#63;>  

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>用戶注冊</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 ><legend >用戶注冊</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>&nbsp;</td> 
   <td><input type="submit" name="sub" value="注冊" /> 
     <input type="reset" name="res" value="重置" /></td> 
  </tr> 
 </table></fieldset> 
</form> 
</body> 
</html>  

3、index_ok.php

<&#63;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");//對輸入的密碼進(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'>注冊成功。</font>";//如果結(jié)果為真提示注冊成功 
    }else{ 
      echo "<font color='green'>注冊失敗!</font>";//否則提示注冊失敗 
    } 
  }else{ 
    echo "請認(rèn)真填寫用戶名和密碼!";//提示輸入用戶名和密碼 
  } 
&#63;>  

二、運行結(jié)果

注冊成功后,數(shù)據(jù)庫顯示如下:

crypt加密如何在php項目中使用

關(guān)于crypt加密如何在php項目中使用就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI