인터넷정보

GD 이미지 및 랜덤 함수를 이용한 스팸광고 글쓰기 막기

알 수 없는 사용자 2008. 2. 19. 12:31



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

반응형