pastebin.com
#1 paste tool since 2002
new
archive
help
API
Leave subdomain
Subdomain Archive
Subdomain Posts
Anonymous
PHP
| 3 days ago
Sam Yong
PHP
| 160 days ago
Sam Yong
PHP
| 162 days ago
Sam Yong
PHP
| 197 days ago
Sam Yong
PHP
| 209 days ago
Sam Yong
PHP
| 250 days ago
Sam Yong
PHP
| 432 days ago
Sam Yong
PHP
| 478 days ago
Sam Yong
PHP
| 568 days ago
Sam Yong
PHP
| 568 days ago
Recent Posts
Anonymous
Python
| 5 sec ago
Anonymous
None
| 27 sec ago
Anonymous
None
| 43 sec ago
Anonymous
None
| 1 min ago
Anonymous
None
| 2 min ago
Anonymous
None
| 2 min ago
Anonymous
C++
| 2 min ago
Anonymous
None
| 2 min ago
Anonymous
None
| 2 min ago
Anonymous
None
| 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our
help page
.
hide message
By Sam Yong on the 14th of Jul 2009 08:07:52 AM
Download
|
Raw
|
Embed
|
Report
<?php
session_start
(
)
;
// note that $_GET['k'] is a static key that you can enter when getting the image.
// generate the key and store into session
$_SESSION
[
'captchasecurity'
]
=
md5
(
mt_rand
(
)
.
time
(
)
.
$session_hash
)
.
$session_hash
.
md5
(
$_GET
[
'k'
]
.
mt_rand
(
)
)
;
// create a shorter key for display
$key
=
dechex
(
crc32
(
$_SESSION
[
'captchasecurity'
]
)
)
;
// disable the client side caching
header
(
'Content-type: image/png'
)
;
header
(
'Cache-Control: max-age=0'
)
;
header
(
'Expires: '
.
gmdate
(
'r'
,
time
(
)
-
3600
*
24
*
365
)
)
;
header
(
'Pragma:'
)
;
// randomize the background image
$r
=
mt_rand
(
0
,
3
)
;
$captcha
=
imagecreatefrompng
(
'img/captcha'
.
$r
.
'.png'
)
;
$cl
=
mt_rand
(
0
,
50
)
;
$c
=
imagecolorallocate
(
$captcha
,
$cl
,
$cl
,
$cl
)
;
$line
=
imagecolorallocate
(
$captcha
,
233
,
239
,
239
)
;
$txtx
=
imagefontwidth
(
5
)
*
strlen
(
$key
)
+
10
;
$txty
=
imagefontheight
(
5
)
;
$timg1
=
imagecreate
(
$txtx
,
$txtx
)
;
$ba
=
imagecolorallocatealpha
(
$timg1
,
0
,
0
,
0
,
127
)
;
imagefilledrectangle
(
$timg1
,
0
,
0
,
$txtx
,
$txtx
,
$ba
)
;
imagesavealpha
(
$timg1
,
true
)
;
$tc
=
imagecolorallocate
(
$timg1
,
$cl
,
$cl
,
$cl
)
;
imagestring
(
$timg1
,
5
,
0
,
$txtx
/
2
-
$txty
/
2
,
$key
,
$tc
)
;
$tca
=
imagecolorallocatealpha
(
$timg1
,
255
,
255
,
255
,
127
)
;
$timg
=
imagerotate
(
$timg1
,
mt_rand
(
-
5
,
5
)
,
$tca
)
;
imagesavealpha
(
$timg
,
true
)
;
imagecopy
(
$captcha
,
$timg
,
mt_rand
(
2
,
22
)
,
mt_rand
(
3
,
6
)
,
0
,
$txtx
/
2
-
$txty
/
2
,
$txtx
,
$txtx
)
;
// output the captcha image
imagepng
(
$captcha
)
;
// free up memory
imagedestroy
(
$timg
)
;
imagedestroy
(
$timg1
)
;
imagedestroy
(
$captcha
)
;
?>
Submit a correction or amendment below.
Make A New Post
<?php session_start(); // note that $_GET['k'] is a static key that you can enter when getting the image. // generate the key and store into session $_SESSION['captchasecurity'] = md5(mt_rand().time().$session_hash).$session_hash.md5($_GET['k'].mt_rand()); // create a shorter key for display $key = dechex(crc32($_SESSION['captchasecurity'])); // disable the client side caching header('Content-type: image/png'); header('Cache-Control: max-age=0'); header('Expires: '.gmdate('r',time()-3600*24*365)); header('Pragma:'); // randomize the background image $r = mt_rand(0,3); $captcha = imagecreatefrompng('img/captcha'.$r.'.png'); $cl = mt_rand(0,50); $c = imagecolorallocate($captcha, $cl, $cl, $cl); $line = imagecolorallocate($captcha,233,239,239); $txtx = imagefontwidth(5) * strlen($key) +10; $txty = imagefontheight(5); $timg1 = imagecreate($txtx,$txtx); $ba = imagecolorallocatealpha($timg1,0, 0, 0,127); imagefilledrectangle($timg1, 0, 0, $txtx, $txtx, $ba); imagesavealpha($timg1, true); $tc = imagecolorallocate($timg1, $cl, $cl, $cl); imagestring($timg1, 5, 0, $txtx/2 - $txty/2, $key, $tc); $tca = imagecolorallocatealpha($timg1, 255, 255, 255,127); $timg = imagerotate($timg1, mt_rand(-5,5), $tca); imagesavealpha($timg, true); imagecopy($captcha, $timg, mt_rand(2,22), mt_rand(3,6), 0, $txtx/2 - $txty/2, $txtx, $txtx); // output the captcha image imagepng($captcha); // free up memory imagedestroy($timg);imagedestroy($timg1); imagedestroy($captcha); ?>
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Bash
C
C++
CSS
HTML
Java
JavaScript
Lua
None
Perl
PHP
Python
Rails
----------------------------
ABAP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
APT Sources
ASM (NASM)
ASP
AutoIt
Avisynth
Bash
Basic4GL
BibTeX
Blitz Basic
BNF
BOO
BrainFuck
C
C for Macs
C Intermediate Language
C#
C++
CAD DCL
CAD Lisp
CFDG
Clone C
Clone C++
CMake
COBOL
ColdFusion
CSS
D
DCS
Delphi
Diff
DIV
DOS
DOT
Eiffel
Email
Erlang
FO Language
Fortran
FreeBasic
Game Maker
Genero
GetText
Groovy
Haskell
HQ9 Plus
HTML
IDL
INI file
Inno Script
INTERCAL
IO
Java
Java 5
JavaScript
KiXtart
Latex
Linden Scripting
Lisp
Loco Basic
LOL Code
Lotus Formulas
Lotus Script
LScript
Lua
M68000 Assembler
Make
MatLab
MatLab
mIRC
Modula 3
MPASM
MXML
MySQL
None
NullSoft Installer
Oberon 2
Objective C
OCalm Brief
OCaml
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Pascal
PAWN
Per
Perl
PHP
PHP Brief
Pic 16
Pixel Bender
PL/SQL
POV-Ray
Power Shell
Progress
Prolog
Properties
ProvideX
Python
QBasic
Rails
REBOL
REG
Robots
Ruby
Ruby Gnuplot
SAS
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
SQL
T-SQL
TCL
TCL
Tera Term
thinBasic
TypoScript
unrealScript
VB.NET
VeriLog
VHDL
VIM
Visual Pro Log
VisualBasic
VisualFoxPro
WhiteSpace
WHOIS
Win Batch
XML
Xorg Config
XPP
Z80 Assembler
Post expiration:
Never
10 Minutes
1 Hour
1 Day
1 Month
Post exposure:
Public
Private
Name / Title:
Email: