帮忙看下PHP验证码问题出在哪里?

帮忙看下PHP验证码问题出在哪里?

我的注册页面zhuce.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form name=zhuce action=reg.php method=post>
<table>
  <tbody>
  <tr>
    <td>用户名:</td>
        <td><input type=text name=username></td>
        <td>用户名长度为4~18个字符</td>
  </tr></tbody></table>
<table>
  <tbody>
  <tr>
    <td>登陆密码:</td>
        <td><input type=text name=password></td>
        <td rowspan=2>密码长度6~16位,字母区分大小写</td></tr>
  <tr>
    <td>重复登陆密码:</td>
        <td><input type=text name=cpassword></td>
  </tr></tbody></table>
<table>
  <tbody>
    <tr>
    <td>性别:</td>
        <td><input type=radio name= value=0 checked>男   <input type=radio name= value=1>女</td></tr>
  <tr>
    <td>真实姓名:</td>
        <td><input type=text name=firstname></td>
  </tr></tbody></table>
<table>
  <tbody>
  <tr>
    <td>保密邮箱:</td>
        <td><input type=text name=mail></td>
        <td>填写、验证保密邮箱,通行证安全有保障</td>
  </tr></tbody></table>
<table>
  <tbody>
  <tr>
    <td>验证码:</td>
        <td><input type=text name=usercheckcode><img alt=使用PHP实现登陆验证码 src=checknumber.php?act=init>
</td>
        <td></td>
  </tr></tbody></table>
<input type=submit value=注册帐号 title=确认注册>
</form>
</body>
</html>

这是我的验证码checknumber.php
<?php
session_start();

if($act == "init")
{
    Header("Content-type: image/png");
    srand(microtime() * 100000);
    $login_check_number = strval(rand("1111","9999"));

    session_register("login_check_number");
    $h_img = imagecreate(40,17);
    $c_black = ImageColorAllocate($h_img, 0,0,0);
    $c_white = ImageColorAllocate($h_img, 255,255,255);
    imageline($h_img, 1, 1, 350, 25, $c_black);
    imagearc($h_img, 200, 15, 20, 20, 35, 190, $c_white);
    imagestring($h_img, 5, 2, 1, $login_check_number, $c_white);
    ImagePng($h_img);
    ImageDestroy($h_img);

    die();
}
?>

提交页面reg.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<?php
$name=$_POST['username'];
$passw=$_POST['password'];
$=$_POST[''];
$fname=$_POST['firstname'];
$mail=$_POST['mail'];
$checkcode=$_POST['usercheckcode'];

$sql="insert into members (username,password,,firstname,mail)
     values ('$name','$passw','$','$fname','$mail')";

include_once("./checknumber.php");
if($number != $login_check_number || empty($number))
{
    print("校验码不正确!");
    die();
}

require('connect.php');
if($result)
{
echo '恭喜操作成功!<p>';
}
?>
</body>
</html>
可是老是出错,"校验码不正确",不知道错在哪,请高手帮帮忙,谢谢了
PHP我喜欢!

act是通过url参数传过去的,在checknumber.php里要用 $_GET['act']
判断时就是和session的login_check_number的值比较。而不是又将include_once("./checknumber.php");这样login_check_number就是新的了,而不是图片中看到的。还有就是$number 是什么?实在看不出来。是$checkcode吧?

[复制到剪切板]
CODE:
<?php 
session_start
();
?>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<
title>无标题文档</title>
</
head>
<
body>
<?
php
$name
=$_POST['username'];
$passw=$_POST['password'];
$=
$_POST[''];
$fname=$_POST['firstname'];
$mail=$_POST['mail'];
$checkcode=$_POST['usercheckcode'];

$sql="insert into members (username,password,,firstname,mail)
     values ('
$name','$passw','$','$fname','$mail')";

//include_once("./checknumber.php");
if($checkcode != $_SESSION['login_check_number'] || empty($number))
{
    print(
"校验码不正确!");
    die();
}

require(
'connect.php');
if(
$result

echo 
'恭喜操作成功!<p>'

?>
</
body>
</
html> ;

还是不行的话请检查一下$_SESSION['login_check_number']是否有值或者正确吧

[ 本帖最后由 我不是鱼 于 2007-12-11 17:09 编辑 ]
如履薄冰

太谢谢你了,终于成功了,爱死你们了
PHP我喜欢!

~!说我么~!