Gentics Portal.Node PHP API
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
All
Classes
Namespaces
Functions
Variables
Pages
common
modules
fg
assets
elements
captcha
securimage
examples
display_value.php
1
<?php
2
3
/**
4
* Display Value Captcha Example
5
* 2012-04-18
6
* @version 3.2RC2 (April 2012)
7
*
8
* This example shows how to use the "display_value" option in Securimage which
9
* allows the application to define the code that will be displayed on the
10
* captcha image.
11
*
12
* Note: This value is not stored in the session or database! The display_value
13
* parameter would be used by a 3rd party application that uses Securimage only
14
* to display captcha images, but generates and manages the codes independently.
15
*
16
*/
17
18
// Set debugging
19
error_reporting(E_ALL);
20
ini_set(
'display_errors'
, 1);
21
22
// Defines Securimage class
23
require_once
'../securimage.php'
;
24
25
// Create an array of options to give to Securimage
26
// This example sets the captcha text to the current time
27
// In order to use the display_value, a captchaId must be supplied so a random one is created
28
// Next we set turn off some unnecessary options and set properties of captcha
29
// image_width makes the image wide enough to hold the time
30
// no_session tells Securimage not to start or use a session to store codes
31
// no_exit tells Securimage not to terminate after calling Securimage::show()
32
// use_sqlite_db tells Securimage not to use SQLite
33
// send_headers tells Securimage not to send HTTP headers for the image; by not
34
// sending headers, you can capture the output and save it to file or serve it
35
// to the browser
36
37
$options = array(
'display_value'
=> date(
'h:i:s a'
),
38
'captchaId'
=> sha1(uniqid($_SERVER[
'REMOTE_ADDR'
] . $_SERVER[
'REMOTE_PORT'
])),
39
'image_width'
=> 250,
40
'no_session'
=>
true
,
41
'no_exit'
=>
true
,
42
'use_sqlite_db'
=>
false
,
43
'send_headers'
=>
false
);
44
45
// construct new Securimage object with the given options
46
$img =
new
Securimage
($options);
47
48
// show the image using the supplied display_value
49
// this demonstrates how to use output buffering to capture the output
50
51
ob_start();
// start the output buffer
52
$img->show();
// output the image so it is captured by the buffer
53
$imgBinary = ob_get_contents();
// get contents of the buffer
54
ob_end_clean();
// turn off buffering and clear the buffer
55
56
header(
'Content-Type: image/png'
);
57
header(
'Content-Length: '
. strlen($imgBinary));
58
59
echo $imgBinary;
60
Generated on Thu Jun 20 2013 14:45:15 for Gentics Portal.Node PHP API by
1.8.1.2