温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-12-09 16:04:51 来源:亿速云 阅读:151 作者:Leah 栏目:开发技术

这篇文章将为大家详细讲解有关crypt加密如何在php项目中使用,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

一、代码

1、conn.php

<&#63;php 
  $conn = mysql_connect("localhost", "root", "111") or die("连接数据库服务器失败!".mysql_error()); //连接MySQL服务器 
  mysql_select_db("db_database21",$conn);     //选择数据库db_database21 
  mysql_query("set names utf8");           //设置数据库编码格式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");//包含数据库连接文件 
  if(trim($_POST['user'])!= "" and trim($_POST['pwd'])!= ""){//判断输入是否为空 
    $pwd = crypt($_POST['pwd'],"key");//对输入的密码进行crypt加密 
    $sql = "insert into tb_user(username,password)values('".$_POST[user]."','". $pwd."')";//定义sql语句 
    $result = mysql_query($sql,$conn);//执行sql语句 
    if($result){ 
      echo "<font color='red'>注册成功。</font>";//如果结果为真提示注册成功 
    }else{ 
      echo "<font color='green'>注册失败!</font>";//否则提示注册失败 
    } 
  }else{ 
    echo "请认真填写用户名和密码!";//提示输入用户名和密码 
  } 
&#63;>  

二、运行结果

注册成功后,数据库显示如下:

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

关于crypt加密如何在php项目中使用就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI