密码强度检测

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!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=gb2312" />
<title>
密码强度检测
</title>
<style type="text/css">
body{font:12px/1.5 Arial;} input{float:left;font-size:12px;width:150px;font-family:arial;border:1px
solid #ccc;padding:3px;} input.correct{border:1px solid green;} input.error{border:1px
solid red;} #tips{float:left;margin:2px 0 0 20px;} #tips span{float:left;width:50px;height:20px;color:#fff;overflow:hidden;background:#ccc;margin-right:2px;line-height:20px;text-align:center;}
#tips.s1 .active{background:#f30;} #tips.s2 .active{background:#fc0;} #tips.s3
.active{background:#cc0;} #tips.s4 .active{background:#090;}
</style>
<script type="text/javascript">
window.onload = function() {
var oTips = document.getElementById("tips");
var oInput = document.getElementsByTagName("input")[0];
var aSpan = oTips.getElementsByTagName("span");
var aStr = ["弱", "中", "强", "非常好"];
var i = 0;

oInput.onkeyup = oInput.onfocus = oInput.onblur = function() {
var index = checkStrong(this.value);
this.className = index ? "correct": "error";
oTips.className = "s" + index;
for (i = 0; i < aSpan.length; i++) aSpan[i].className = aSpan[i].innerHTML = "";
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1])
}
};
/** 强度规则
+ ------------------------------------------------------- +
1) 任何少于6个字符的组合,弱;任何字符数的同类字符组合,弱;
2) 任何字符数的两类字符组合,中;
3) 12位字符数以下的三类或四类字符组合,强;
4) 12位字符数以上的三类或四类字符组合,非常好。
+ ------------------------------------------------------- +
**/
//检测密码强度
function checkStrong(sValue) {
var modes = 0;
if (sValue.length < 6) return modes;
if (/\d/.test(sValue)) modes++; //数字
if (/[a-z]/.test(sValue)) modes++; //小写
if (/[A-Z]/.test(sValue)) modes++; //大写
if (/\W/.test(sValue)) modes++; //特殊字符
switch (modes) {
case 1:
return 1;
break;
case 2:
return 2;
case 3:
case 4:
return sValue.length < 12 ? 3 : 4
break;
}
}
</script>
</head>

<body>
<input type="password" value="" maxlength="16" />
<div id="tips">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</body>

</html>

php和c++socket通讯(基于字节流,二进制)

研究了一下PHP和C++socket通讯,用C++作为服务器端,php作为客户端进行.

socket通讯是基于协议的,因此,只要双方协议一致就行.

关于协议的选择:我看过网上大部分协议都是在应用层的协议,选用这样的协议很方便,基本上就是字符串传过来,传过去

本次研究的协议算是当今国际化的一个标准做法.length+flag+body(长度+类型+内容)的方式,

total_length code flag length1 string1 length2 string2
总长度 操作类型 标志 字符串1长度 字符串1 字符串2长度 字符串2
4字节 2字节 4字节(暂时无用) 2字节 x字节 2字节 x字节

php实现方式,也很容易,通过pack打包成二进制进行通讯.下面贴一下代码

Read More

PHP 魔术方法__set() __get() 方法详解

__set() is run when writing data to inaccessible properties.
__get() is utilized for reading data from inaccessible properties.

究竟用中文怎么翻译呢? inaccessible :n. 难达到;难接近;无法理解。
有代码有真相:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php  
error_reporting(E_ALL);
class stu{
private $a;
private $b = 0;
public $c;
public $d = 0;
//这里的 private 可以用 protected public 替代
private function __get($name) {
return 123;
}
//这里的 private 也可以用 protected public 替代
private function __set($name, $value) {
echo "This is set function";
}
}
$s = new stu();
var_dump($s->a); //output: 123
var_dump($s->b); //output: 123
var_dump($s->c); //output: null
var_dump($s->d); //output: 0
var_dump($s->e); //output: 123
$s->a = 3; //output: This is set function
$s->c = 3; //no output
$s->f = 3; //output: This is set function
?>

Read More

PHP超级全局变量总结

PHP有9个预定义变量数组,分别总结如下:

1、$_SERVER

$_SERVER超级全局变量包含由web服务器创建的信息,它提供了服务器和客户配置及当前请求环境的有关信息。根据服务器不同,$_SERVER中的变量值和变量个数会有差别,不过一般都可以找到CGI1.1规范中定义的变量。其中包括:

$_SERVER[ ‘HTTP_REFERER’ ] ; 引导用户到达当前位置的页面的URL ;

$_SERVER[ ‘REMOTE_ADDR‘ ] ; 客户IP地址 ;

$_SERVER[ ’REQUEST_URI‘ ] ; URL的路径部分。如果URL是http://www.example.com/blog/apache/index.html ,那么URI就是/blog/apache/index.html 。

$_SERVER[ ‘HTTP_USER_AGENT’ ] ; 客户的用户代理,一般会提供操作系统和浏览器的有关信息。

Read More