-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathdisplay_value.php
60 lines (49 loc) · 2.27 KB
/
display_value.php
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
<?php
/**
* Display Value Captcha Example
* 2016-12-04
*
* This example shows how to use the "display_value" option in Securimage which
* allows the application to define the code that will be displayed on the
* captcha image.
*
* Note: This value is not stored in the session or database! The display_value
* parameter would be used by a 3rd party application that uses Securimage only
* to display captcha images, but generates and manages the codes independently.
*
*/
// Set debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Defines Securimage class
require_once __DIR__ . '/../securimage.php';
// Create an array of options to give to Securimage
// This example sets the captcha text to the current time
// In order to use the display_value, a captchaId must be supplied so a random one is created
// Next we set turn off some unnecessary options and set properties of captcha
// image_width makes the image wide enough to hold the time
// no_session tells Securimage not to start or use a session to store codes
// no_exit tells Securimage not to terminate after calling Securimage::show()
// use_sqlite_db tells Securimage not to use SQLite
// send_headers tells Securimage not to send HTTP headers for the image; by not
// sending headers, you can capture the output and save it to file or serve it
// to the browser
$options = array('display_value' => date('h:i:s a'),
'image_width' => 270,
'image_height' => 80,
'no_session' => true,
'no_exit' => true,
'use_database' => false,
'use_memcached' => false,
'send_headers' => false);
// construct new Securimage object with the given options
$img = new Securimage($options);
// show the image using the supplied display_value.
// This demonstrates how to use output buffering to capture the output.
// Note: It isn't required to use 'no_exit' and 'send_headers' or output buffering
// in conjunction with display value. Doing so is a common use case and serves to show
// 2 examples in 1.
ob_start(); // start the output buffer
$img->show(); // output the image so it is captured by the buffer
header('Content-Type: image/png');
ob_end_flush(); // end output buffering and flush the image out