If the posting process is input.php -> process.php,
1. Create othr_img_rndm.php and upload it and font files attached.
2. Insert the following to input.php:
<?php
session_start();
...
$_SESSION['key'] = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
?>
<img src='othr_img_rndm.php?<?php echo time(); ?>' /> <br />
Insert the above numbers: <input type='text' name='n_txt' />
...
3. Insert the following to process.php:
<?php
session_start();
...
if($_SESSION['key'] AND $_POST['n_txt']==$_SESSION['key']) {
process post ...
}
else echo "failed";
$_SESSION['key'] = NULL;
...
?>
* This code snippet requires GD library installed.
othr_img_rndm_test.php:
<?php
//session_save_path('bbs/data/__zbSessionTMP');
session_start();
if(isset($_POST['n_txt'])) {
if($_SESSION['key'] AND $_POST['n_txt']==$_SESSION['key'] AND $_POST['n_hddn']=='') echo "succeeded";
else echo "failed";
$_SESSION['key'] = NULL;
?>
<input type='button' value='back' onclick="window.location.href='<?php echo $_SERVER['PHP_SELF']; ?>';" />
<?php
} else {
$_SESSION['key'] = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
echo "$_SESSION['key'] = ".$_SESSION['key'].'<br />';
?>
<img src='othr_img_rndm.php?<?php echo time(); ?>'
style='visibility:hidden;' onload="this.style.visibility='visible';" /><br />
<form name='n_frm' method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
Insert the above characters: <input type='text' name='n_txt' />
<input type='text' name='n_hddn' value='' style='visibility:hidden;' />
<input type='submit' />
</form>
<?php
}
?>
othr_img_rndm.php:
<?php
//session_save_path('bbs/data/__zbSessionTMP');
session_start();
header("Content-type: image/png");
$arry = array(
$_SERVER['DOCUMENT_ROOT'].'/'.'arial' .'.ttf'
,$_SERVER['DOCUMENT_ROOT'].'/'.'cour' .'.ttf'
,$_SERVER['DOCUMENT_ROOT'].'/'.'verdana'.'.ttf'
,$_SERVER['DOCUMENT_ROOT'].'/'.'tahoma' .'.ttf');
$wdth = 50; $hght = 20;
$img = imagecreate($wdth,$hght);
$clr_bckgrnd = imagecolorallocate($img,200,200,200);
$clr_frgrnd = imagecolorallocate($img,0,0,0);
imagefilledrectangle($img,0,0,$wdth,$hght,$clr_bckgrnd);
imagettftext($img,rand(11,13),rand(-10,10),10,16,$clr_frgrnd,$arry[rand(0,3)],substr($_SESSION['key'],0,1));
imagettftext($img,rand(11,13),rand(-10,10),17,16,$clr_frgrnd,$arry[rand(0,3)],substr($_SESSION['key'],1,1));
imagettftext($img,rand(11,13),rand(-10,10),24,16,$clr_frgrnd,$arry[rand(0,3)],substr($_SESSION['key'],2,1));
imagettftext($img,rand(11,13),rand(-10,10),31,16,$clr_frgrnd,$arry[rand(0,3)],substr($_SESSION['key'],3,1));
imagepng($img);
imagedestroy($img);
?>
example:
http://www.qindex.info/Q_get.php?g_clss=forum&g_prcss=thrd&g_tmplt=&g_brd=5&g_pg=1&g_thrd=102
http://www.qindex.info/Q_incld/othr_img_rndm_test.php
reference:
http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=58446&page=4
'인터넷정보' 카테고리의 다른 글
Header("Content-type: text/xml"); (0) | 2008.02.26 |
---|---|
Header("Content-type: text/xml"); (0) | 2008.02.26 |
[스크립트] 동적 테이블 (최하단행추가,특정행삭제) (0) | 2008.02.19 |
[스크립트] 동적 테이블 (최하단행추가,특정행삭제) (0) | 2008.02.19 |
GD 이미지 및 랜덤 함수를 이용한 스팸광고 글쓰기 막기 (0) | 2008.02.19 |
확장자(파일)에 연결프로그램 등록/초기화/변경이 잘 안되면 이렇게.. (0) | 2008.02.18 |
확장자(파일)에 연결프로그램 등록/초기화/변경이 잘 안되면 이렇게.. (0) | 2008.02.18 |
양력/음력 간지,절기,띠,국경일,기념일 MySql DB 자료 (1) | 2008.02.16 |
양력/음력 간지,절기,띠,국경일,기념일 MySql DB 자료 (0) | 2008.02.16 |
[함수] URL 관리(Template_ 버젼) (0) | 2008.02.14 |