PHP simple captcha


PHP용 심플 captcha


https://github.com/claviska/simple-php-captcha


thx to Cory LaViska.


   사용법소개



   데모 소스


위의 라이브러리를 가지고 직접 데모를 만들어 보았다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?
session_start();
include("simple-php-captcha.php");
 
$PREV_Captcha = $_SESSION['captcha']['code'];
$POST_Captcha = $_POST['captcha'];
if ( !empty($PREV_Captcha) && !empty($POST_Captcha) )
{
    if( strcasecmp($PREV_Captcha, $POST_Captcha) != 0 )
    {
        echo "<script>alert('이미지에 출력된 글자와 다릅니다.');</script>";
    }else{
        echo "<script>alert('정상');</script>";
    }
}//end if
 
$_SESSION['captcha'] = simple_php_captcha();
?>
 
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- meta -->
    <meta name="Author" content="serpiko@hanmail.net" />
    <meta name="description" content="http://serpiko.tistory.com" />
 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
    <meta name="format-detection" content="telephone=no" />
     
    <!-- link -->
    <link rel="stylesheet" type="text/css" href="" />
 
    <!-- script -->
    <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
    <title>Document</title>
    <style>
        * {
            box-sizing: border-box;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
        }
    </style>
</head>
<body>
    <div id="wrap">
        <form method='post' action='<?=$PHP_SELF?>'>
            PREV_Captcha : <input type='text' size='100' value='<?=$PREV_Captcha?>' /> <br />
            POST_Captcha : <input type='text' name='' size='100' value='<?=$POST_Captcha?>' /> <br /><br />
     
            할당된 캡챠<br />
            <img src="<?=$_SESSION['captcha']['image_src']?>" style='width:100px;border:1px solid blue;border-radius:7px;' /><br /><br />
                 
            사용자 캡챠 입력<br />
            captcha : <input type='text' size='100' name='captcha' value="" /> <br />
 
            <button type='submit'>확인</button>
        </form>
    </div>
 
</body>
</html>


   데모 보기






출처: http://serpiko.tistory.com/589 [삽SAP(Study And Programming) 질 블로그. by허정진]

'프로그래밍 > php' 카테고리의 다른 글

PHP Simple HTML DOM Parser  (0) 2018.02.27
정규식 예제  (0) 2018.02.27
컨텐츠 내용중 첫번째 IMG주소 뽑아내기  (0) 2018.02.27
GD  (0) 2018.02.27
날짜 or 시간  (0) 2018.02.27

## 기간 일 구하기

	echo intval((strtotime(종료일) - strtotime(시작일)) / 86400);


## 날짜 몇분전 으로 표시

	// $date1:기준시간	timestamp
	// $date2:계산할시간	timestamp
	function getGlobalDate($date1, $date2) {
		$dtDiff = $date1 - $date2;
		
		if($dtDiff < 60) $rs = intval($dtDiff) . "/sec";
		else if($dtDiff < 60*60) $rs = intval($dtDiff / (60)) . "/min";
		else if($dtDiff < 60*60*24) $rs = intval($dtDiff / (60*60)) . "/hour";
		else if($dtDiff < 60*60*24*7) $rs = intval($dtDiff / (60*60*24)) . "/day";
		else if($dtDiff < 60*60*24*30) $rs = intval($dtDiff / (60*60*24*7)) . "/week";
		else if($dtDiff < 60*60*24*365) $rs = intval($dtDiff / (60*60*24*30)) . "/month";
		else $rs = intval($dtDiff / (60*60*24*365)) . "/year";
		
		return $rs;
	}


## 남은시간 계산

	/*
	설  명
		해당시간의 남은시간 계산함수
		사용예
			diff_time(timestamp)
			리턴값
			배열
	*/
	function diff_time( $timestamp ) {
		$date1 = $timestamp;
		$date2 = time();
		$total_secs = abs($date1-$date2);
		$diff_in_days = floor( $total_secs / 86400 );
		$rest_hours = $total_secs % 86400;
		$diff_in_hours = floor( $rest_hours / 3600 );
		$rest_mins = $rest_hours % 3600;
		$diff_in_mins = floor( $rest_mins / 60 );
		$diff_in_secs = floor( $rest_mins % 60 );

		$time_diff["days"] = (int)($diff_in_days);
		$time_diff["hours"] = $diff_in_hours;
		$time_diff["mins"] = $diff_in_mins;
		$time_diff["secs"] = $diff_in_secs;
		return $time_diff;
	}


## 한시간 전 날짜와 시간 구하기

	echo date("Y-m-d H:i:s", mktime(date("H")-1, date("i"), date("s"), date("m"), date("d"), date("Y")));

	15일전 날짜 구하기
	$date = date('Y-m-d H:i:s', strtotime('-15 day'));

	타임스템프 변환 
	$sch_end_date = '2017-01-30 23:59:59';
	$timestamp =  strtotime($sch_end_date);
	echo date('Y-m-d H:i:s', $timestamp); exit;


	$time = time();
	date("Y-m-d",strtotime("-1 day", $time)); // 하루 전(어제)
	date("Y-m-d",strtotime("-1 day", $time)); // 하루 전(어제)
	date("Y-m-d",strtotime("now", $time)); // 현재
	date("Y-m-d",strtotime("+1 day", $time)); // 하루 후(내일)
	date("Y-m-d",strtotime("+1 week", $time)); // 일주일 후
	date("Y-m-d",strtotime("-1 month", $time)); // 한달 전
	date("Y-m-d",strtotime("+1 month", $time)); // 다음달
	date("Y-m-d",strtotime("+6 month", $time)); // 6달후
	date("Y-m-d",strtotime("+12 month", $time)); // 12달후
	date("Y-m-d",strtotime("next Thursday", $time)); // 다음주 목요일
	date("Y-m-d",strtotime("last Monday", $time)); // 지난 월요일
	date("Y-m-d",strtotime("10 September 2000", $time)); // 2000년 9월 10일
	date("Y-m-d", strtotime('first day of')) // 해당월의 1일
	date("Y-m-d:i:s", strtotime("now", $time)); //현재 시간
	date("Y-m-d:i:s", strtotime("+5 minutes", $time)); //현재 시간에서 5분 후


## 한주의 시작일과 마지막일 구하기

	$today = date("Ymd");

	$week_day = date("w", mktime(0, 0, 0, substr($today, 4, 2), substr($today, 6, 2), substr($today, 0, 4)) );
	$week_start = date("Ymd", mktime(0, 0, 0, substr($today, 4, 2), substr($today, 6, 2)-$week_day, substr($today, 0, 4)) );

	$week_day2 = 6 - $week_day;
	$week_end = date("Ymd", mktime(0, 0, 0, substr($today, 4, 2), substr($today, 6, 2)+$week_day2, substr($today, 0, 4)) );

	echo $week_start ."~". $week_end;


'프로그래밍 > php' 카테고리의 다른 글

PHP Simple HTML DOM Parser  (0) 2018.02.27
정규식 예제  (0) 2018.02.27
컨텐츠 내용중 첫번째 IMG주소 뽑아내기  (0) 2018.02.27
GD  (0) 2018.02.27
captcha  (0) 2018.02.27

+ Recent posts