forked from LimeSurvey/LimeSurvey
-
Notifications
You must be signed in to change notification settings - Fork 3
/
verification.php
124 lines (110 loc) · 3.14 KB
/
verification.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: verification.php 8639 2010-04-26 14:58:08Z c_schmitz $
*/
// Security Checked: POST, GET, SESSION, REQUEST, returnglobal, DB
// make sure you include this file only if the ImageCreate function does exist since it is an optional library
// Lets get into the session
require_once(dirname(__FILE__).'/config-defaults.php');
require_once(dirname(__FILE__).'/common.php');
if (isset($_GET['sid'])) $surveyid=(int)$_GET['sid']; else die();
$usquery = "SELECT stg_value FROM ".db_table_name("settings_global")." where stg_name='SessionName'";
$usresult = db_execute_assoc($usquery,'',true); //Checked
if ($usresult)
{
$usrow = $usresult->FetchRow();
$stg_SessionName=$usrow['stg_value'];
if ($surveyid)
{
@session_name($stg_SessionName.'-runtime-'.$surveyid);
}
else
{
@session_name($stg_SessionName.'-runtime-publicportal');
}
}
else
{
session_name("LimeSurveyRuntime-$surveyid");
}
session_set_cookie_params(0,$relativeurl.'/');
@session_start();
// header for png
Header("Content-Type: image/png");
// Create Image
$im = ImageCreate(75, 20);
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
$red = ImageColorAllocate($im, 255, 0, 0);
$blue = ImageColorAllocate($im, 0, 0, 255);
$grey_shade = ImageColorAllocate($im, 204, 204, 204);
// Create the random numberes
srand((double)microtime()*1000000);
$num1 = rand(1,5);
$found = false;
while ($found == false)
{
$num2 = rand(1,100);
if (preg_match('/^[0-9]+$/', $num2/5))
{
$found = true;
break;
}
}
$font_c_rand = rand(1,3);
if ($font_c_rand == 1)
{
$font_color = $black;
} else if ($font_c_rand == 2)
{
$font_color = $red;
} else if ($font_c_rand == 3)
{
$font_color = $blue;
}
$font_rand = rand(1,3);
if ($font_rand == 1)
{
$font = $rootdir."/fonts/verabd.ttf";
} else if ($font_rand == 2) {
$font = $rootdir."/fonts/vera.ttf";
} else if ($font_rand == 3)
{
$font = $rootdir."/fonts/verait.ttf";
}
$line_rand = rand(1,3);
if ($line_rand == 1)
{
$line_color = $black;
} else if ($line_rand == 2)
{
$line_color = $red;
} else if ($line_rand == 3)
{
$line_color = $blue;
}
// Fill image, make transparent
ImageFill($im, 0, 0, $grey_shade);
//imagecolortransparent ($im, $white);
imageline($im,0,0,0,20,$line_color);
imageline($im,74,0,74,19,$line_color);
imageline($im,0,0,74,0,$line_color);
imageline($im,0,19,74,19,$line_color);
// Write math question in a nice TTF Font
ImageTTFText($im, 10, 0, 3, 16,$font_color, $font, $num1." + ".$num2." =" );
// Display Image
ImagePNG($im);
ImageDestroy($im);
// Add the answer to the session
$_SESSION['secanswer'] = $num1+$num2;
?>