我使用的是开源平台 PHPCMS 2008 sp4
所有代码如下!
SQL 数据表CREATE TABLE `phpcms`.`yimacn_productsn` (
`pid` INT( 13 ) UNSIGNED NOT NULL ,
`pname` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
`pdescription` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;
html 代码<script language=javascript>
<!--
function check(){
if (chaxun.zkzh.value==""){
alert("请输入你的产品代码!");
chaxun.pcid.focus(); return false;
}
var filter=/^\s*[.A-Za-z0-9_-]{6,20}\s*$/;
if (!filter.test(chaxun.zkzh.value))
{
alert("你的产品代码填写不正确,请重新填写!");
chaxun.zkzh.focus();
return false;
} return True;
}
//-->
</script>
<table width="600" height="295" border="0" align="center" cellpadding="0" cellspacing="0" background:#666666; >
<!--DWLayoutTable-->
<tr>
<td width="600" height="200"><table width="406" border="0" align="center">
<form method="post" name="chaxun" action="checksn.php" target="_blank" onSubmit="return check();">
<tr>
<td width="90"><div align="right">产品序列号:</div></td>
<td width="306"><div align="left">
<input name="zkzh" type="text" class=input size="20" onMouseOver ="this.style.backgroundColor='#ffffff'" onMouseOut ="this.style.backgroundColor='#f0ffff'">
</div></td>
</tr>
<tr>
<td><div align="right">随机验证:</div></td>
<td>
<div align="left"><input type="text" /><input name="checkcodestr" id="checkcodestr" type="text" size="8" style="ime-mode:disabled;"> <img src="checkcode.php" id="checkcode" onclick="this.src='checkcode.php?id='+Math.random()*5;" style="cursor:pointer;" alt="验证码,看不清楚?请点击刷新验证码" align="absmiddle"/></div></td>
</tr>
<tr>
<td><br/></td>
<td><div align="left"> <input type="submit" name="submit" value="查询产品信息" class="button" onmouseover ="this.style.backgroundColor='#dcdcdc'" onmouseout ="this.style.backgroundColor='#999999'" />
</div></td>
</tr></form>
</table></td>
</tr>
</table>
checksn.php
<?php
$conn = mysql_connect("localhost","admin","admin") or die("Could not connect to MySQL server!");
mysql_select_db("phpcms",$conn);
mysql_query("set names utf8"); $zkzh = $_POST['zkzh'];
$query = mysql_query('select * from phpcms_pmsn where pid='.$zkzh);
$row = mysql_fetch_array($query);
if (is_array($row))
{
echo $row['pid'] . '<br>';
echo $row['pname'] . '<br>';
echo $row['pdescription'] . '<br>';
}
else
{
echo '没有该编号的相关信息';
}?>
checkcode.php 代码
<?php
require dirname(__FILE__).'/include/common.inc.php';session_start();$enablegd = 1;
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imageline','imagedestroy','imagecolorallocatealpha','imageellipse','imagepng');
foreach($funcs as $func)
{
if(!function_exists($func))
{
$enablegd = 0;
break;
}
}
if(!function_exists('ob_gzhandler')) ob_clean();if($enablegd)
{
//create captcha
$consts = 'cdfgkmnpqrstwxyz23456';
$vowels = 'aek23456789';
for ($x = 0; $x < 6; $x++)
{
$const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1);
$vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1);
}
$radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
$_SESSION['checkcode'] = $string = substr($radomstring,0,4); //only display 4 str
//set up image, the first number is the width and the second is the height
$imageX = strlen($radomstring)*8; //the image width
$imageY = 20; //the image height
$im = imagecreatetruecolor($imageX,$imageY); //creates two variables to store color
$background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
$foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255)));
$foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80);
$middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160));
$middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80); //fill image with bgcolor
imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
//writes string
if(function_exists('imagettftext'))
{
imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ALGER.TTF', $string[0]);
imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ARIALNI.TTF', $string[1]);
imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ALGER.TTF', $string[2]);
imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/arial.ttf', $string[3]);
}
else
{
imagestring($im, 5, 3, floor(rand(0,5))-1, $string[0], $foregroundArr[rand(0,3)]);
imagestring($im, 5, 16, floor(rand(0,5))-1, $string[1], $foregroundArr[rand(0,3)]);
imagestring($im, 5, 23, floor(rand(0,5))-1, $string[2], $foregroundArr[rand(0,3)]);
imagestring($im, 5, 33, floor(rand(0,5))-1, $string[3], $foregroundArr[rand(0,3)]);
}
//strikethrough $border = imagecolorallocate($im, 133, 153, 193);
//imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back);
imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border); $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
for ($i=0;$i<80;$i++)
{
imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
}
//random shapes
for ($x=0; $x<9;$x++)
{
if(mt_rand(0,$x)%2==0)
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2);
}
else
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
}
}
//output to browser
header("content-type:image/png\r\n");
imagepng($im);
imagedestroy($im);
}
else
{
$files = glob(PHPCMS_ROOT.'images/checkcode/*.jpg');
if(!is_array($files)) exit($LANG['please_check_dir_images_checkcode']); $checkcodefile = $files[rand(0, count($files)-1)];
$_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4); header("content-type:image/jpeg\r\n");
include $checkcodefile;
}
?>
现在的问题是:验证码无法判断是否正确 就是无论我输入什么 都不显示
注明:这个验证码checkcode.php是phpcms 自带的 给登录界面使用的,我就直接使用 应该会有问题,但是我不晓得如何更改,请教下老师们!!!!
所有代码如下!
SQL 数据表CREATE TABLE `phpcms`.`yimacn_productsn` (
`pid` INT( 13 ) UNSIGNED NOT NULL ,
`pname` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
`pdescription` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;
html 代码<script language=javascript>
<!--
function check(){
if (chaxun.zkzh.value==""){
alert("请输入你的产品代码!");
chaxun.pcid.focus(); return false;
}
var filter=/^\s*[.A-Za-z0-9_-]{6,20}\s*$/;
if (!filter.test(chaxun.zkzh.value))
{
alert("你的产品代码填写不正确,请重新填写!");
chaxun.zkzh.focus();
return false;
} return True;
}
//-->
</script>
<table width="600" height="295" border="0" align="center" cellpadding="0" cellspacing="0" background:#666666; >
<!--DWLayoutTable-->
<tr>
<td width="600" height="200"><table width="406" border="0" align="center">
<form method="post" name="chaxun" action="checksn.php" target="_blank" onSubmit="return check();">
<tr>
<td width="90"><div align="right">产品序列号:</div></td>
<td width="306"><div align="left">
<input name="zkzh" type="text" class=input size="20" onMouseOver ="this.style.backgroundColor='#ffffff'" onMouseOut ="this.style.backgroundColor='#f0ffff'">
</div></td>
</tr>
<tr>
<td><div align="right">随机验证:</div></td>
<td>
<div align="left"><input type="text" /><input name="checkcodestr" id="checkcodestr" type="text" size="8" style="ime-mode:disabled;"> <img src="checkcode.php" id="checkcode" onclick="this.src='checkcode.php?id='+Math.random()*5;" style="cursor:pointer;" alt="验证码,看不清楚?请点击刷新验证码" align="absmiddle"/></div></td>
</tr>
<tr>
<td><br/></td>
<td><div align="left"> <input type="submit" name="submit" value="查询产品信息" class="button" onmouseover ="this.style.backgroundColor='#dcdcdc'" onmouseout ="this.style.backgroundColor='#999999'" />
</div></td>
</tr></form>
</table></td>
</tr>
</table>
checksn.php
<?php
$conn = mysql_connect("localhost","admin","admin") or die("Could not connect to MySQL server!");
mysql_select_db("phpcms",$conn);
mysql_query("set names utf8"); $zkzh = $_POST['zkzh'];
$query = mysql_query('select * from phpcms_pmsn where pid='.$zkzh);
$row = mysql_fetch_array($query);
if (is_array($row))
{
echo $row['pid'] . '<br>';
echo $row['pname'] . '<br>';
echo $row['pdescription'] . '<br>';
}
else
{
echo '没有该编号的相关信息';
}?>
checkcode.php 代码
<?php
require dirname(__FILE__).'/include/common.inc.php';session_start();$enablegd = 1;
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imageline','imagedestroy','imagecolorallocatealpha','imageellipse','imagepng');
foreach($funcs as $func)
{
if(!function_exists($func))
{
$enablegd = 0;
break;
}
}
if(!function_exists('ob_gzhandler')) ob_clean();if($enablegd)
{
//create captcha
$consts = 'cdfgkmnpqrstwxyz23456';
$vowels = 'aek23456789';
for ($x = 0; $x < 6; $x++)
{
$const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1);
$vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1);
}
$radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
$_SESSION['checkcode'] = $string = substr($radomstring,0,4); //only display 4 str
//set up image, the first number is the width and the second is the height
$imageX = strlen($radomstring)*8; //the image width
$imageY = 20; //the image height
$im = imagecreatetruecolor($imageX,$imageY); //creates two variables to store color
$background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
$foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255)));
$foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80);
$middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160));
$middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80); //fill image with bgcolor
imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
//writes string
if(function_exists('imagettftext'))
{
imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ALGER.TTF', $string[0]);
imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ARIALNI.TTF', $string[1]);
imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ALGER.TTF', $string[2]);
imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/arial.ttf', $string[3]);
}
else
{
imagestring($im, 5, 3, floor(rand(0,5))-1, $string[0], $foregroundArr[rand(0,3)]);
imagestring($im, 5, 16, floor(rand(0,5))-1, $string[1], $foregroundArr[rand(0,3)]);
imagestring($im, 5, 23, floor(rand(0,5))-1, $string[2], $foregroundArr[rand(0,3)]);
imagestring($im, 5, 33, floor(rand(0,5))-1, $string[3], $foregroundArr[rand(0,3)]);
}
//strikethrough $border = imagecolorallocate($im, 133, 153, 193);
//imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back);
imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border); $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
for ($i=0;$i<80;$i++)
{
imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
}
//random shapes
for ($x=0; $x<9;$x++)
{
if(mt_rand(0,$x)%2==0)
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2);
}
else
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
}
}
//output to browser
header("content-type:image/png\r\n");
imagepng($im);
imagedestroy($im);
}
else
{
$files = glob(PHPCMS_ROOT.'images/checkcode/*.jpg');
if(!is_array($files)) exit($LANG['please_check_dir_images_checkcode']); $checkcodefile = $files[rand(0, count($files)-1)];
$_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4); header("content-type:image/jpeg\r\n");
include $checkcodefile;
}
?>
现在的问题是:验证码无法判断是否正确 就是无论我输入什么 都不显示
注明:这个验证码checkcode.php是phpcms 自带的 给登录界面使用的,我就直接使用 应该会有问题,但是我不晓得如何更改,请教下老师们!!!!
解决方案 »
- 缩略图的问题,麻烦知道的帮我下,急!!!!!!!!!
- include_path问题
- 为什么这段代码导出EXCEL有错?
- 调用 生成XML代码 的问题
- 菜鸟求知:在windows下用php5能否连上linux下的oracle数据库,如何连接,请大侠指教?
- PHP返回值截取
- 欧易亚科技股份有限公司~广州诚聘PHP程序员(数名)
- 哪位来看看我写的分页程序?为什么翻页的连接没有用?
- ASP.NET推出了,到底是ASP有前途还是PHP有前途?为什么现在公司都要PHP设计员,不要ASP设计员?
- 用php怎么从数据库调出数据显示到页面上
- 出现这样子的错误提示,什么原因?
- 类中的css是另外创建一个类引用过来还是直接写在当前的类中?
你这里不是存入Session一个变量值么在你登陆的时候判断。去除键为checkcode的。跟你页面输入的值比对
最好使用Ajax判断否则用户还要退回提交页面。
$checkcodestr=$_POST['checkcodestr'];
if($checkcodestr != $_SESSION['checkcode'])
{
echo '验证码错误';
}不知他的$_SESSION['checkcode']有没有加密 如果有加密的话你再把取到的$checkcodestr用相同的方式加密完之后再比较
在checksn.php开头加上楼上提供的代码。
不过改一下,楼上写得有点多余session_start();if($_POST['checkcodestr'] != $_SESSION['checkcode'])
{
echo '验证码错误';
exit();
}