01
<%
02
Call
Com_CreatValidCode(Request.QueryString(
"tel"
))
03
Public
Sub
Com_CreatValidCode(pTel)
04
'----------禁止緩存
05
Response.Expires = 0
06
Response.AddHeader
"Pragma"
,
"no-cache"
07
Response.AddHeader
"cache-ctrol"
,
"no-cache"
08
Response.ContentType =
"Image/BMP"
09
Randomize
10
Dim
i, ii, iii ,rndColor,strLen,sql,rs
11
Const
cOdds = 5
'------------雜點出現的機率
12
Const
str=
"0123456789-"
13
strLen = len(pTel)
14
rndColor = ChrB(cint(rnd*255)) & ChrB(cint(rnd*255)) & ChrB(cint(rnd*255))
15
'-----------顏色的數據(字符,背景)
16
Dim
vColorData(1)
17
'vColorData(0) = ChrB(0) & ChrB(0) & ChrB(0) '----藍0,綠0,紅0(黑色)
18
'vColorData(1) = ChrB(255) & ChrB(255) & ChrB(255) '----藍250,綠236,紅211(淺藍色)
19
'vColorData(0) = ChrB(197) & ChrB(106) & ChrB(49) '---- 藍0,綠0,紅0(黑色)
20
'vColorData(1) = ChrB(238) & ChrB(210) & ChrB(193) '-----藍250,綠236,紅211(淺藍色)
21
vColorData(0) = ChrB(0) & ChrB(0) & ChrB(0)
'---------藍0,綠0,紅0(黑色)
22
vColorData(1) = ChrB(205) & ChrB(237) & ChrB(245)
'------------藍250,綠236,紅211(淺藍色)
23
24
'--------------------隨機產生字符
25
Randomize
26
Dim
vCode()
27
redim vCode(strLen-1)
28
For
i = 0
To
strLen-1
29
vCode(i) =instr(1,str,mid(pTel,i+1,1),1)-1
30
Next
31
32
'-----------字符的數據
33
Dim
vNumberData(11)
34
'Verdana Font
35
vNumberData(0) =
"11111111111000111101110111011101110111011101110111011101110111011110001111111111"
36
vNumberData(1) =
"11111111111101111110011111110111111101111111011111110111111101111110001111111111"
37
vNumberData(2) =
"11111111111000111101110111011101111110111111011111101111110111111100000111111111"
38
vNumberData(3) =
"11111111111000111101110111111101111100111111110111111101110111011110001111111111"
39
vNumberData(4) =
"11111111111110111111001111101011111010111101101111100001111110111111100111111111"
40
vNumberData(5) =
"11111111110000011101111111011111110000111111110111111101110111011110001111111111"
41
vNumberData(6) =
"11111111111000111101101111011111110000111101110111011101110111011110001111111111"
42
vNumberData(7) =
"11111111110000011101101111111011111101111111011111110111111101111111011111111111"
43
vNumberData(8) =
"11111111111000111101110111011101111000111101110111011101110111011110001111111111"
44
vNumberData(9) =
"11111111111000111101110111011101110111011110000111111101111011011110000111111111"
45
vNumberData(10) =
"11111111111111111111111111111111111111111100000111111111111111111111111111111111"
46
vNumberData(11) =
"11111111111111111111111111111111111111111111111111111111111111111111111111111111"
47
'-----------------輸出圖像文件頭 <br>
48
Response.BinaryWrite ChrB(66) & ChrB(77) &chrb(((strLen*8*10*3+54) mod 256)) & chrb(((strLen*8*10*3+54)\ 256)mod 256) & ChrB((((strLen*8*10*3+54)\ 256)\256)mod 256) & ChrB(((((strLen*8*10*3+54)\ 256)\256)\256)mod 256) & ChrB(0) & ChrB(0) &_
49
ChrB(0) & ChrB(0) & ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) &_
50
ChrB(0) & ChrB(0) & ChrB(strLen*8) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(10) & ChrB(0) &_
51
ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0)
52
'------------------輸出圖像信息頭
53
Response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)&_
54
ChrB((strLen*8*10*3)mod 256)&ChrB(((strLen*8*10*3)\256)mod 256)&ChrB((((strLen*8*10*3)\256)\256)mod 256)&ChrB(((((strLen*8*10*3)\256)\256)\256)mod 256)&_
55
ChrB(196) & ChrB(14) & ChrB(0) & ChrB(0) & ChrB(196) & ChrB(14)&ChrB(0) & ChrB(0) &_
56
ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
57
For
i = 9
To
0
Step
-1
'----------歷經所有行
58
For
ii = 0
To
strLen-1
'-------歷經所有字
59
For
iii = 1
To
8
'--------歷經所有像素
60
'---------逐行、逐字、逐像素地輸出圖像數據
61
If
Rnd * 99 + 1 < cOdds
Then
'---------隨機生成雜點
62
Response.BinaryWrite rndColor
63
Else
64
Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 8 + iii, 1))
65
End
If
66
Next
67
Next
68
Next
69
End
Sub
70
%>
(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)將以上代碼保存為img.asp,在要顯示電話號碼的位置插入<img src="img.ASP?tel=010-0000000">即可。