/var/www/hkosl.com/securexpert/vendor/dapphp/securimage/StorageAdapter/Session.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
<?php

namespace Securimage\StorageAdapter;

use 
Securimage\StorageAdapter\AdapterInterface;

class 
Session implements AdapterInterface
{
    protected 
$session_name;

    public function 
__construct($options null)
    {
        if (!empty(
$options) && is_array($options)) {
            if (isset(
$options['session_name'])) {
                
$this->session_name $options['session_name'];
            }
        }

        
$this->bootstrap();
    }

    public function 
store($captchaId$captchaInfo)
    {
        if ((
function_exists('session_status') && PHP_SESSION_ACTIVE == session_status()) || session_id() != '') {
            
$_SESSION['securimage_data'][$captchaId] = $captchaInfo;

            return 
true;
        }

        return 
false;
    }

    public function 
storeAudioData($captchaId$audioData)
    {
        if (isset(
$_SESSION['securimage_data'][$captchaId]) &&
            
$_SESSION['securimage_data'][$captchaId] instanceof \Securimage\CaptchaObject
        
) {
            
$_SESSION['securimage_data'][$captchaId]->captchaAudioData $audioData;
            return 
true;
        }

        return 
false;
    }

    public function 
get($captchaId$what null)
    {
        if (isset(
$_SESSION['securimage_data'][$captchaId])) {
            return 
$_SESSION['securimage_data'][$captchaId];
        }

        return 
null;
    }

    public function 
delete($captchaId)
    {
        unset(
$_SESSION['securimage_data'][$captchaId]);

        return 
true;
    }

    protected function 
bootstrap()
    {
        if ( 
session_id() == '' || (function_exists('session_status') && PHP_SESSION_NONE == session_status()) ) {
            
// no session has been started yet (or it was previousy closed), which is needed for validation
            
if (!is_null($this->session_name) && trim($this->session_name) != '') {
                
session_name(trim($this->session_name)); // set session name if provided
            
}
            
session_start();
        }

        if (!isset(
$_SESSION['securimage_data'])) {
            
$_SESSION['securimage_data'] = [];
        }
    }
}