:
<?php session_name('mysession');
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Captcha</title>
</head>
<body>
Captcha Image:
<img src="get_captcha.php" width="139" height="139" />
<?php
echo 'Captcha text:'.$_SESSION['random_number']
?>
</body>
</html>
및 get_captcha.php은 다음과 같습니다
<?php
session_name('mysession');
session_start();
$string = '';
for ($i = 0; $i < 5; $i++) {
$string .= chr(rand(97, 122));
}
$_SESSION['random_number'] = $string;
$dir = 'fonts/';
$image = imagecreatetruecolor(165, 50);
// random number 1 or 2
$num = rand(1,2);
if($num==1)
{
$font = "Capture it 2.ttf"; // font style
}
else
{
$font = "Molot.otf";// font style
}
// random number 1 or 2
$num2 = rand(1,2);
if($num2==1)
{
$color = imagecolorallocate($image, 113, 193, 217);// color
}
else
{
$color = imagecolorallocate($image, 163, 197, 82);// color
}
$white = imagecolorallocate($image, 255, 255, 255); // background color white
imagefilledrectangle($image,0,0,399,99,$white);
imagettftext ($image, 30, 0, 10, 40, $color, $dir.$font, $_SESSION['random_number']);
imagepng($image);
?>
문제는 그 나는 시험을 처음 실행할 때 정의되지 않은 인덱스 : -captcha.php 나는 다음과 같은 오류 얻을 라인 (17)에 시험 captcha.php에서 RANDOM_NUMBER ($ _SESSION [ 'RANDOM_NUMBER는'] 설정되지 않습니다 !!)
$ 페이지를 새로 고침 한 후 _SESSION [ 'rando m_number ']는 이전 captcha 텍스트를 표시합니다! 아무도 이런 일이 발생하는 이유를 모르십니까 ?????? 때문에 처음 세션의
는
내가이 솔루션하지만 방법에 대해 많은 검색, :)되지 여기 get_captcha.php –
같은 문제에 임의의 숫자 테스트 captcha.php와에 $ _SESSION을 설정하려고 –