4.字符集操作原理与乱码解决方案

show character set;

显示出字符集校对
show variables like "%character%";
show variables like "%collation%";
显示环境变量
+----------------------------+--------------------------------+
| Variable_name                   | Value                                       |
+----------------------------+--------------------------------+
| character_set_client           | gbk                                          |
| character_set_connection | gbk                                          |
| character_set_database     | utf8                                         |
| character_set_filesystem   | binary                                      |
| character_set_results         | gbk                                          |
| character_set_server          | latin1                                       |
| character_set_system        | utf8                                          |
| character_sets_dir              | D:\XAMPP\mysql\share\charsets\ |
+----------------------------+--------------------------------+
character_set_server            | latin1    默认操作字符集
character_set_system           | utf8    系统元数据字符集
 character_set_database     | utf8   当前选中的数据库字符集
character_set_filesystem   | binary  文件系统字符       
drop database if exists u;    如果存在u数据库就执行删除
create database u default character set utf8;
show databases;
use u;
create table user(name char(30) character set gbk) default character set utf8;
show create table user\G
create table user(name char(30) character set gbk) default character set utf8;
show create table user\G
select * from user;
alter table user modify name char(30) character set utf8;    修改表的字符集
show create table user\G
实现了字符的转换
set names gbk;
set names utf8;
set character_set_result=utf8;
create table user(id int(10) primary key auto_increment , username char(30) ,password char(32) , tel char(12) , qq char(12)) default character set gbk;
desc user;
insert into user (username , password , tel , qq) values("admin" ,md5("admin") ,15051986853 ,1440016892);
其中的md5是加密的一种方式
验证登录php脚本
<?php
header('Content-Type:image/png');
header('Content-Type:no-cache');
header('Pragma:no-cache');
header('Expires:0');
setcookie('userName', 'Tommy');
$w=90;//图片的宽
$h=30;//图片的高
//在服务器端内存中创建图片
$img=imagecreatetruecolor($w, $h);
//分配一个新的颜色
$c = imagecolorallocate($img,  rand(180,240),  rand(180,240),  rand(180,240));
//在图像向画个矩形,当背景色
imagefilledrectangle($img,  0, 0,  $w,  $h,  $c);
$src = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
$code = '' ;
for($i =0; $i<4; $i++){
$code  .=  $src[ rand(0, strlen($src) )]; 
}
$c = imagecolorallocate($img,  rand(60,160),  rand(60,160),  rand(60,160));
imagestring( $img,  5,  20, 7, $code,  $c);
//把图片发送给客户端
imagepng($img);
imagedestroy($img); //在服务器内存中销毁此图片
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值