我想用验证码发生器女巫是这样工作的:_SESSION不可见里面的captcha文件
1)除一些安全文字$ _SESSION变量 2)显示captha形象。
<img src="http://www.website.ro/captcha/captcha_source.php">
人机识别图像是一个PHP文件,该文件读取$ _SESSION [ “security_text”],生成图像,通过将其设定-S包头加到一个图像:
header("Content-type:image/jpeg");
header("Content-Disposition:inline ; filename=secure.jpg");
3)比较submited text to the one stored inside _SESSION
问题: -I set $ _SESSION [“outside”] =“outside”;在图片标签之前,但在captcha_source.php中,$ _SESSION变量是空的。
- 如果我在captcha_source.php的开头给它session_start(),session_id与网站的其余部分相同,但是_SESSION仍然是空的。
- 如果我设置$ _SESSION [“里面”] =“里面”;在captcha_source.php里面,当我读取captcha_source.php之外的SESSION(在img标签之后)时,SESSION只包含[“outside”] =“outside”。 (并在里面captcha_source,会话打印为里面=>里面)
- 如果我删除img src = captcha_source.php行,并设置SESSION为“测试”并在表单中写入“测试”,一切工作后提交(但我没有图像,因为它没有包括在内)。
- 如果不是将文件包含在image标签中,而是将其包含为包含“/captcha/captcha_source.php”,它会设置会话正常,但我需要图像而不是垃圾文本。
因此,会话在页面之间工作,但不知何故在captcha_soruce.php里面。即使这些身份证是相同的,会议缝合完全独立。
一个直觉是,这个问题是来自htaccess的(但相同的会话ID-S很奇怪),也许从这些线:(验证码文件夹被区别对待,但基址应是不变的)
RewriteCond $1 !^(index_ro|imagini|extra|fisiere|slider|tinymce|captcha)
RewriteRule ^(.*)/ index_ro.php?$1/
也许相同的会话与我读取文件的方式有关:从captcha_source.php中删除头文件并打开与同一浏览器(firefox)相同的文件www.site.ro/captcha/captcah_source.php。我看到我印刷的垃圾文本和会话ID以及会话变量。使用相同的网站打开多个标签,保持相同的标识。
我希望不会太久,但是我一直在解决这个问题已经过去了2天。如果它不起作用,我会用sql来做这件事,但我想知道问题出在哪里,所以在其他情况下不会再出现。
谢谢:)
,这里是一个精简的代码来展示一下hapens:
//the form part
<?php
session_start();
echo session_id(); //prints the same as on all pages
//the form was not submittted
if(!$_POST["mail_form_captcha"])
{
unset($_SESSION); //just to be sure nothing remains from older sessions
//generate form that has a field "mail_form_captcha"
[...]
//generate a random text for captcha and put it in security_text
InitCaptcha();
$_SESSION["before"]="before";
?>
<img src="<?php echo "./captcha/image.php"; ?>" />
<?php
//include "./captcha/image.php"; //if uncoment this line, everything works, but the image is included as garbage text
$_SESSION["after"]="after";
print_r($_SESSION); //this prints [security_text] => 10 [before] => before [after] => after
}
else //interpret the submission
{
print_r($_SESSION); //this is empty if session_start() is at the beginning of captcha_source.php, otherwise only contains before after and security_text
}
?>
//the captcha part
<?php
session_start(); //if included, it erases the session from the other files, otherwise it leaves it intact :-/
$_SESSION["inside"]="inside";
print_r($_SESSION); //this prints [inside] => inside
echo session_id(); //this prints the same session id as on the rest of the pages
[...]
imagettftext([...] $_SESSION["security_text"]); //this draws a blank image
[...]
header("Content-type:image/jpeg");
header("Content-Disposition:inline ; filename=secure.jpg");
imagejpeg($img);
?>
你叫'session_start'吗?你使用自定义会话ID还是会话名称? – netcoder
您可以发布captcha_soruce.php的相关部分(即session_start导致$ _SESSION调用),因为这可能是中间弄乱了东西。 – Robbie
@netcoder是的,我确实在每个页面的顶部和captcha_source.php中调用了session_start。但我没有使用自定义会话ID或名称。 –