|
PHP image Verification 问题
[复制链接]
|
|

楼主 |
发表于 1-12-2006 06:19 PM
|
显示全部楼层
vImage.php
<?
class vImage{
var $numChars = 3; # Tamanho da String: default 3;
var $w; # Largura da imagem
var $h = 20; # Altura da Imagem: default 15;
var $colBG = "188 220 231";
var $colTxt = "0 0 0";
var $colBorder = "0 128 192";
var $charx = 20; # Espaço lateral de cada char
var $numCirculos = 10; #Numeros de circulos randomicos
function vImage(){
session_start();
}
function gerText($num){
# receber tamanho da string
if (($num != '')&&($num > $this->numChars)) $this->numChars = $num;
# gerar string randmica
$this->texto = $this->gerString();
$_SESSION['vImageCodS'] = $this->texto;
}
function loadCodes(){
$this->postCode = $_POST['vImageCodP'];
$this->sessionCode = $_SESSION['vImageCodS'];
}
function checkCode(){
if (isset($this->postCode)) $this->loadCodes();
if ($this->postCode == $this->sessionCode)
return true;
else
return false;
}
function showCodBox($mode=0,$extra=''){
$str = "<input type=\"text\" name=\"vImageCodP\" ".$extra." > ";
if ($mode)
echo $str;
else
return $str;
}
function showImage(){
$this->gerImage();
header("Content-type: image/png");
ImagePng($this->im);
}
function gerImage(){
# Calcular tamanho para caber texto
$this->w = ($this->numChars*$this->charx) + 40; #5px de cada lado, 4px por char
# Criar img
$this->im = imagecreatetruecolor($this->w, $this->h);
#desenhar borda e fundo
imagefill($this->im, 0, 0, $this->getColor($this->colBorder));
imagefilledrectangle ( $this->im, 1, 1, ($this->w-2), ($this->h-2), $this->getColor($this->colBG) );
#desenhar circulos
for ($i=1;$i<=$this->numCirculos;$i++) {
$randomcolor = imagecolorallocate ($this->im , rand(100,255), rand(100,255),rand(100,255));
imageellipse($this->im,rand(0,$this->w-10),rand(0,$this->h-3), rand(20,60),rand(20,60),$randomcolor);
}
#escrever texto
$ident = 20;
for ($i=0;$i<$this->numChars;$i++){
$char = substr($this->texto, $i, 1);
$font = rand(4,5);
$y = round(($this->h-15)/2);
$col = $this->getColor($this->colTxt);
if (($i%2) == 0){
imagechar ( $this->im, $font, $ident, $y, $char, $col );
}else{
imagecharup ( $this->im, $font, $ident, $y+10, $char, $col );
}
$ident = $ident+$this->charx;
}
}
function getColor($var){
$rgb = explode(" ",$var);
$col = imagecolorallocate ($this->im, $rgb[0], $rgb[1], $rgb[2]);
return $col;
}
function gerString(){
rand(0,time());
$possible="AGHacefhjkrStVxY124579";
while(strlen($str)<$this->numChars)
{
$str.=substr($possible,(rand()%(strlen($possible))),1);
}
$txt = $str;
return $txt;
}
}
#dooms@terra.com.br# ?> |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 06:19 PM
|
显示全部楼层
img.php
<?
include("vImage.php");
$vImage = new vImage();
$vImage->gerText($_GET['size']);
$vImage->showimage();
?> |
|
|
|
|
|
|
|
发表于 1-12-2006 06:22 PM
|
显示全部楼层
原帖由 skycs 于 1-12-2006 06:17 PM 发表
试了。对那个code它能看到。但对其他的看不到。
不是很明白。
如果用9楼的code,你的result是什么? |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 06:29 PM
|
显示全部楼层
原帖由 hui_wooi 于 1-12-2006 06:22 PM 发表
不是很明白。
如果用9楼的code,你的result是什么?
如果用9楼的code它能fully function。我的意思是对我刚刚post的code没起作用。麻烦了。 |
|
|
|
|
|
|
|
发表于 1-12-2006 06:44 PM
|
显示全部楼层
原帖由 skycs 于 1-12-2006 06:29 PM 发表
如果用9楼的code它能fully function。我的意思是对我刚刚post的code没起作用。麻烦了。
9楼的code,它显示什么?
你刚刚post的code,它又显示什么? |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 07:02 PM
|
显示全部楼层
原帖由 hui_wooi 于 1-12-2006 06:44 PM 发表
9楼的code,它显示什么?
你刚刚post的code,它又显示什么?
它可以显示图案了咯。我post的不可以显示图案。 |
|
|
|
|
|
|
|
发表于 1-12-2006 09:09 PM
|
显示全部楼层
原帖由 skycs 于 1-12-2006 07:02 PM 发表
它可以显示图案了咯。我post的不可以显示图案。
我的code告诉你有了gd是吗?
你最新post上来的code无法显示图案,是吗?
 |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 11:07 PM
|
显示全部楼层
原帖由 ikanyuchiew 于 1-12-2006 09:09 PM 发表
我的code告诉你有了gd是吗?
你最新post上来的code无法显示图案,是吗?
是的.对不起,让大家这么麻烦.你的code告诉我有了gd.之前那个可以显示了.最新那个不知为何不能显示. |
|
|
|
|
|
|
|
发表于 1-12-2006 11:09 PM
|
显示全部楼层
原帖由 skycs 于 1-12-2006 11:07 PM 发表
是的.对不起,让大家这么麻烦.你的code告诉我有了gd.之前那个可以显示了.最新那个不知为何不能显示.
方便的话,print screen上来。
看它到底怎么了。 |
|
|
|
|
|
|
|
发表于 2-12-2006 02:00 AM
|
显示全部楼层
原帖由 skycs 于 1-12-2006 11:07 PM 发表
是的.对不起,让大家这么麻烦.你的code告诉我有了gd.之前那个可以显示了.最新那个不知为何不能显示.
我看过你新贴的 code 没问题,只是输出时有点问题。
不要问我为甚麽,我也不会答。
但是可以改少许就可以输出图片了,不知到你要吗?
请看下图看是不是你要得。(将下面的link有空隔的连起来)
//http://i10.t i n y p i c.com/309ug7r.png
[ 本帖最后由 blue333 于 2-12-2006 02:28 AM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 2-12-2006 12:55 PM
|
显示全部楼层
原帖由 blue333 于 2-12-2006 02:00 AM 发表
我看过你新贴的 code 没问题,只是输出时有点问题。
不要问我为甚麽,我也不会答。
但是可以改少许就可以输出图片了,不知到你要吗?
请看下图看是不是你要得。(将下面的link有空隔的连起来)
...
谢谢你的意见。可是那个图片为什么颠倒的啊?基本上是可以的知识号码颠倒了。
可以知道你是怎么改的吗? |
|
|
|
|
|
|
|
发表于 2-12-2006 02:18 PM
|
显示全部楼层
原帖由 skycs 于 2-12-2006 12:55 PM 发表
谢谢你的意见。可是那个图片为什么颠倒的啊?基本上是可以的知识号码颠倒了。
可以知道你是怎么改的吗?
原来你可以看到那号码的?
因为是code把它弄颠倒的。 |
|
|
|
|
|
|
|

楼主 |
发表于 2-12-2006 03:12 PM
|
显示全部楼层
原帖由 hui_wooi 于 2-12-2006 02:18 PM 发表
原来你可以看到那号码的?
因为是code把它弄颠倒的。
不是的。我的意思是刚刚blue333 post上来的link里面的号码是倒反的。我的是直接不能看到。 |
|
|
|
|
|
|
|
发表于 2-12-2006 03:55 PM
|
显示全部楼层
请在 vImage.php 改:
function showImage(){
$this->gerImage();
header("Content-type: image/png");
ImagePng($this->im,"123.png");
}
请在 form.php 改:
<?
include("vImage.php");
$vImage = new vImage();
$vImage->gerText(6);
$vImage->showimage();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#006699">
<form name="form1" method="post" action="verify.php">
<tr bordercolor="#FFFFFF" bgcolor="#3399CC">
<td colspan="2" align="center"><font color="#FFFFFF" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>Verification Image<br>
Imagem de Verificacao </strong></font> </td>
</tr>
<tr bordercolor="#FFFFFF">
<td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font></td>
</tr>
<tr bordercolor="#FFFFFF">
<td colspan="2"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><img src="123.png"></font></div></td>
</tr>
<tr bordercolor="#FFFFFF">
<td width="25%" nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Please enter the code you see above*: <br>
Por favor digite o texto da imagem*: </font></td>
<td width="75%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<?
$vImage->showCodBox(1);
?>
</font></td>
</tr>
<tr bordercolor="#FFFFFF">
<td colspan="2" align="center" nowrap>
<input type="submit" name="Submit" value="Send / Enviar">
</td>
</tr>
<tr bordercolor="#FFFFFF">
<td colspan="2" nowrap><font size="1" face="Verdana, Arial, Helvetica, sans-serif">*Code <strong>is</strong> Case-Sensitive<br>
O codigo <strong>e sensivel</strong> a Caixa Alta/Baixa</font></td>
</tr>
</form>
</table>
<div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">author: <a href="mailto:dooms@terra.com.br">Rafael "DoomsDay" Dohms</a></font><br>
</div>
</body>
</html>
<?
?> |
|
|
|
|
|
|
|
发表于 2-12-2006 04:49 PM
|
显示全部楼层
原帖由 blue333 于 2-12-2006 03:55 PM 发表
请在 vImage.php 改:
function showImage(){
$this->gerImage();
header("Content-type: image/png" ...
其实这code没有错。
不需要改正啊。 |
|
|
|
|
|
|
|

楼主 |
发表于 2-12-2006 04:57 PM
|
显示全部楼层
原帖由 hui_wooi 于 2-12-2006 04:49 PM 发表
其实这code没有错。
不需要改正啊。
可是为什么它不能显示呢? |
|
|
|
|
|
|
|
发表于 2-12-2006 05:36 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 2-12-2006 06:05 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 2-12-2006 06:17 PM
|
显示全部楼层
原帖由 skycs 于 2-12-2006 04:57 PM 发表
可是为什么它不能显示呢?
就好像我在29楼说的。
方便的话,print screen上来。
看它到底怎么了。 |
|
|
|
|
|
|
|
发表于 2-12-2006 10:13 PM
|
显示全部楼层
原帖由 hui_wooi 于 2-12-2006 06:17 PM 发表
就好像我在29楼说的。
方便的话,print screen上来。
看它到底怎么了。
我想不用放图上来也很简单的可以用文字来形容。
那图片在 IE 里显示一个四方形中间一个红色交差。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|