和smarty没关系。
用php和验证码,一搜一大把

解决方案 »

  1.   

    验证码我知道怎么做,如果不用模板,我可以正常使用,可是一用模板(用的是smarty),就出了问题,把代码列在下面,各位高手帮着看看哈:validate_code.php //生成验证码的文件<?php
    session_start();
    header ("Content-type: image/jpeg");for($Tmpa=0;$Tmpa<4;$Tmpa++){
            $nmsg.=rand(0,9);
    }
    $_SESSION['validate_code'] = $nmsg;
    $im = @imagecreate (48, 18)
        or die ("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate ($im, 239, 239, 239);//设置干扰像素,防止被OCR
    for ($i=0;$i<=128;$i++)
     {
     $point_color = imagecolorallocate ($im, rand(0,255), rand(0,255), rand(0,255));
     imagesetpixel($im,rand(2,128),rand(2,38),$point_color);
     }//逐个画上验证码字符
    for ($i=0;$i<=3;$i++)
     {
     $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255));
     $x = $i * 12;
     $y = rand(5,10);
     imagechar ($im, 5, $x, 2,  $_SESSION['validate_code']{$i}, $text_color);
     }//输出PNG图像
    imagepng ($im);imagedestroy ($im);
    ?> index.php //登录界面<?php
    require_once "./includes/global.php";
    $tpl->display("index.htm");
    ?>index.htm //登录界面模板
    <html>
    <head>登录</head>
    <body>
    <form name="login" method="post" action="login.php">
    用户名:<input type="text" name="username" value=""><br>
    密  码:<input type="password" name="password" value=""><br>
    验证码:<input type="text" name="validate_code" value=""><IMG src="./includes/check_code.php" width="46" height="18">
    </body>
    </html>可是传递到login.php以后,发现$_SESSION['validate_code']这个变量不存在,请问我是不是哪里写错了呢?
      

  2.   

    好像模板里面直接读取php文件,session好像是不生效,我好像也碰到过这样的问题,不知道是不是模板哪里还需要进行一下设置顶了,期待高手指导
      

  3.   

    login.php里面session_start()过了没有?
      

  4.   

    login.php里面session_start()过了没有?-------------------------是的,我在这里直接打印$_SEESION['validate_code']都打印不出来,好像是这个变量根本不存在的样子
      

  5.   

    你 print_r($_SESSION); 看有没有这个变量存在
      

  6.   

    你 print_r($_SESSION); 看有没有这个变量存在-------------------------------------------------
    不存在,faint
      

  7.   

    其他session变量都存在,唯独这个用在模板里的不存在~~
      

  8.   

    验证码可以正确显示吗?
    -----------------------
    直接在index.php中答应$_SESSION['validate_code']也不行,也是不存在
      

  9.   

    正常来说在index.php第一次输出肯定是不存在,刷新一次就会出来,我觉得这个跟smarty没有什么关系,你还是再仔细检查你的代码是不是哪里有问题先