查看: 1777|回复: 47
|
PHP image Verification 问题
[复制链接]
|
|
我想请问一下各位,为什么我的php code of image verification不可以看到image的?我找到三个例子,可是三个都不能显示图案?多谢帮忙。。。 |
|
|
|
|
|
|
|
发表于 30-11-2006 11:44 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 30-11-2006 03:07 PM
|
显示全部楼层
原帖由 blue333 于 30-11-2006 11:44 AM 发表
请帖上来看看,这样不知道怎样帮你。
我看过的多数要support GD 2 module...确定你的server有load这个module吗? |
|
|
|
|
|
|
|

楼主 |
发表于 30-11-2006 07:14 PM
|
显示全部楼层
index.php
<?php
session_start();
// Initialize a variable. THIS IS OBSOLETE AND ONLY USED TO PREVENT
// NOTICES ON SOME SYSTEMS. 
$IMGVER_TempString="";
// Now we generate a string that consists of 6 characters that are
// generated randomly. I choose 6, because I didn´t want the user to
// type forever. Of course, any other number would do as well. (NOTE,
// THAT IF YOU USE ANOTHER NUMBER, YOU ALSO HAVE TO EDIT THE IMAGE
// CODE) --> Have a look at the GetRandomChar() function at the bottom
// of this script!
for ($i = 1; $i <= 6; $i++) {
$IMGVER_TempString .= GetRandomChar();
}
// Now we store the text in our session variable.
$HTTP_SESSION_VARS["IMGVER_RndText"] = $IMGVER_TempString;
function GetRandomChar() {
// This function generates our random chars
// Seed with microseconds since last "whole" second
mt_srand((double)microtime()*1000000);
// Create a random number between 1 and 3
$IMGVER_RandVal = mt_rand(1,3);
// If the random number was 1, we generate a lowercase
// character, if it was 2, we generate a number and if
// it was 3, we generate an uppercase character.
switch ($IMGVER_RandVal) {
case 1:
// 97 to 122 are the ASCII codes for lower-
// case characters from a to z.
$IMGVER_RandVal = mt_rand(97, 122);
break;
case 2:
// 48 to 57 are the ASCII codes for the
// numbers from 0 to 9.
$IMGVER_RandVal = mt_rand(48, 57);
break;
case 3:
// 65 to 70 are the ASCII codes for upper-
// case characters from a to z.
$IMGVER_RandVal = mt_rand(65, 90);
break;
}
// Now we return the character, generated from the ASCII code
return chr($IMGVER_RandVal);
}
// BELOW THIS LINE YOU CAN WRITE HTML CODE OR ANYTHING ELSE.
?>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Here comes the HTML
code or any other code you want. Since we did NOT<br />
write anything to the output yet, you might even use <strong>Header()</strong>;</font></p>
<hr size="1" noshade="noshade" />
<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> lease type
the code you see in the image into the textfield below. If you cannot
read the code, just press "<strong>Reload</strong>" to generate
a new one.</font></p>
<p align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><img src="doimg.php?<?php echo SID ?>" /></font></p>
<form action="verificate.php" method=" OST" name="frmImgVerific" target="_self" id="frmImgVerific">
<p> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Enter the code
here: </font>
<input name="txtCode" type="text" id="txtCode" size="30" />
</p>
<p>
<input type="submit" name="Submit" value="OK" />
</p>
</form>
<p align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<B>Note:</b> The code you enter is case sensitive!
</p>
</td>
</tr>
</table> |
|
|
|
|
|
|
|

楼主 |
发表于 30-11-2006 07:15 PM
|
显示全部楼层
doimg.php
<?php
// Create the image with width=150 and height=40
$IMGVER_IMAGE = imagecreate(150,40);
// Allocate two colors (Black & White)
// This uses the RGB names of the colors
$IMGVER_COLOR_BLACK = imagecolorallocate ($IMGVER_IMAGE, 0, 0, 0);
$IMGVER_COLOR_WHITE = imagecolorallocate ($IMGVER_IMAGE, 255, 255, 255);
// Flood Fill our image with black
imagefill($IMGVER_IMAGE, 0, 0, $IMGVER_COLOR_BLACK);
// This handles our session. We get the random text that
// was stored in our session var on the first page.
session_start();
$IMGVER_RandomText = $HTTP_SESSION_VARS["IMGVER_RndText"];
// Since our Text had 6 chars (we defined this not to be longer)
// we now write the 6 random chars in our picture
// For those who don´t know: You can access the third character
//in a string easily by typing $myString[2];
imagechar($IMGVER_IMAGE, 4, 20, 13, $IMGVER_RandomText[0] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 5, 40, 13, $IMGVER_RandomText[1] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 3, 60, 13, $IMGVER_RandomText[2] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 4, 80, 13, $IMGVER_RandomText[3] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 5, 100, 13, $IMGVER_RandomText[4] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 3, 120, 13, $IMGVER_RandomText[5] ,$IMGVER_COLOR_WHITE);
//Now we send the picture to the Browser
header("Content-type: image/jpeg");
imagejpeg($IMGVER_IMAGE);
?> |
|
|
|
|
|
|
|

楼主 |
发表于 30-11-2006 07:16 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 30-11-2006 08:26 PM
|
显示全部楼层
code没问题。
参考ikanyuchiew大大的建议。 |
|
|
|
|
|
|
|
发表于 30-11-2006 08:47 PM
|
显示全部楼层
你的 code 完全没问题,到底出什麽 error message 呢?请贴上来看看。 |
|
|
|
|
|
|
|
发表于 1-12-2006 12:29 AM
|
显示全部楼层
- <?php
- echo (extension_loaded('gd')) ? "yes, i have gd! ^^": "no, i have no gd T.T";
- ?>
复制代码
用这方法检查gd extension是否成功loaded  |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 02:48 AM
|
显示全部楼层
原帖由 ikanyuchiew 于 1-12-2006 12:29 AM 发表
<?php
echo (extension_loaded('gd')) ? "yes, i have gd! ^^": "no, i have no gd T.T";
?>
用这方法检查gd extension是否成功loaded
它不成功叻。什么意思啊?我不是很懂。不成功要怎么办啊?谢谢哦! |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 02:49 AM
|
显示全部楼层
原帖由 blue333 于 30-11-2006 08:47 PM 发表
你的 code 完全没问题,到底出什麽 error message 呢?请贴上来看看。
它没有error message但不能显示图案。
[ 本帖最后由 skycs 于 1-12-2006 02:54 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 1-12-2006 03:35 AM
|
显示全部楼层
用 phpinfo() 看你的gd 开启了吗?
去 php.ini 起动它。 |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 08:38 AM
|
显示全部楼层
原帖由 blue333 于 1-12-2006 03:35 AM 发表
用 phpinfo() 看你的gd 开启了吗?
去 php.ini 起动它。
我在php.ini找不到gd。要怎么开启?我也想问问到底gd是什么来的? 。谢谢各位的帮忙哦! |
|
|
|
|
|
|
|
发表于 1-12-2006 08:48 AM
|
显示全部楼层
gd 是哪来画dynamic graphic 的。 |
|
|
|
|
|
|
|
发表于 1-12-2006 10:39 AM
|
显示全部楼层
原帖由 skycs 于 1-12-2006 08:38 AM 发表
我在php.ini找不到gd。要怎么开启?我也想问问到底gd是什么来的? 。谢谢各位的帮忙哦!
如果你是installed 了php5,那gd和php5是"一起来的",php.ini可以找到 extension = php_gd.dll这条line; 如果没有记错,装置自然是非常简单,如果你是php version< 5,那么我会建议你去
search google, 加油  |
|
|
|
|
|
|
|
发表于 1-12-2006 12:21 PM
|
显示全部楼层
原帖由 skycs 于 1-12-2006 08:38 AM 发表
我在php.ini找不到gd。要怎么开启?我也想问问到底gd是什么来的? 。谢谢各位的帮忙哦!
php.ini
将 ;extension=php_gd2.dll 改成 extension=php_gd2.dll
或
将 ;extension=php_gd.dll 改成 extension=php_gd.dll |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 06:12 PM
|
显示全部楼层
原帖由 blue333 于 1-12-2006 12:21 PM 发表
php.ini
将 ;extension=php_gd2.dll 改成 extension=php_gd2.dll
或
将 ;extension=php_gd.dll 改成 extension=php_gd.dll
谢谢大家的帮忙。我已经改成extension=php_gd.dll。已经可以看到图案了.但是我不知道为什么其他的两个code不能显示。真的是麻烦大家了。
[ 本帖最后由 skycs 于 1-12-2006 06:16 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 1-12-2006 06:14 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 06:17 PM
|
显示全部楼层
原帖由 hui_wooi 于 1-12-2006 06:14 PM 发表
你试了9楼或12楼的方法吗?
试了。对那个code它能看到。但对其他的看不到。 |
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2006 06:18 PM
|
显示全部楼层
form.php
<?
include("vImage.php");
$vImage = new vImage();
?>
<!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 Verificação </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="img.php?size=6"></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 código <strong>é 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> |
|
|
|
|
|
|
| |
本周最热论坛帖子
|