登录验证码,关于smarty模板的问题 和smarty没关系。用php和验证码,一搜一大把 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 验证码我知道怎么做,如果不用模板,我可以正常使用,可是一用模板(用的是smarty),就出了问题,把代码列在下面,各位高手帮着看看哈:validate_code.php //生成验证码的文件<?phpsession_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);//设置干扰像素,防止被OCRfor ($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 //登录界面<?phprequire_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']这个变量不存在,请问我是不是哪里写错了呢? 好像模板里面直接读取php文件,session好像是不生效,我好像也碰到过这样的问题,不知道是不是模板哪里还需要进行一下设置顶了,期待高手指导 login.php里面session_start()过了没有? login.php里面session_start()过了没有?-------------------------是的,我在这里直接打印$_SEESION['validate_code']都打印不出来,好像是这个变量根本不存在的样子 你 print_r($_SESSION); 看有没有这个变量存在 你 print_r($_SESSION); 看有没有这个变量存在-------------------------------------------------不存在,faint 其他session变量都存在,唯独这个用在模板里的不存在~~ 验证码可以正确显示吗?-----------------------直接在index.php中答应$_SESSION['validate_code']也不行,也是不存在 正常来说在index.php第一次输出肯定是不存在,刷新一次就会出来,我觉得这个跟smarty没有什么关系,你还是再仔细检查你的代码是不是哪里有问题先 怎么知道操作系统的版本 怎样用p3p实现跨域设置/读取cookies? 两页面通过session传数组的问题!!! 如何用PHP上传图片?小弟初学,请各位大哥帮忙 超简单问题,新手请教 关于 php连接sybase的问题,帮忙解决。 大家帮忙评价一下我今天新配制的机器如何,价钱合理不?谢谢 怎样判断数据库中的数据没有符合要求的数据?(sql server) php+mysql+apache 中 浏览php网站出错 PHP处理GIF多帧图片问题,请大神指点指点谢谢 这句怎么不能写入文件啊?这句怎么不能写入文件啊? 请问,查询大量数据放在表格中显示出来时怎么减少显示时间?谢谢!
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']这个变量不存在,请问我是不是哪里写错了呢?
不存在,faint
-----------------------
直接在index.php中答应$_SESSION['validate_code']也不行,也是不存在