Source
xxxxxxxxxx
DBexecute('insert into sessions (sessionid, userid) values ('.zbx_dbstr($sessionid).', '.$userid.')');
<?php
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once 'vendor/autoload.php';
require_once dirname(__FILE__).'/../../../include/defines.inc.php';
require_once dirname(__FILE__).'/../../../include/hosts.inc.php';
class CAPIHelper {
// API request id.
protected static $request_id = 0;
// Debug info.
protected static $debug = [];
// Session id.
protected static $session = null;
/**
* Reset API helper state.
*/
public static function reset() {
static::$request_id = 0;
static::clearDebugInfo();
static::setSessionId(null);
}
/**
* Make API call.
*
* @param mixed $data string containing request data as json.
*
* @return array
*
* @throws Exception if API call fails.
*/
public static function callRaw($data) {
global $URL;
if (!is_string($URL)) {
$URL = PHPUNIT_URL.'api_jsonrpc.php';
}
if (is_array($data)) {
$data = json_encode($data);
}
$debug = [
'request' => $data,
'response' => null
];
$params = [
'http' => [
'method' => 'POST',
'content' => $data,
'header' => [
'Content-type: application/json-rpc',
'Content-Length: '.strlen($data)
]
]
];
$handle = @fopen($URL, 'rb', false, stream_context_create($params));
if ($handle) {
$response = @stream_get_contents($handle);
fclose($handle);
}
else {
$php_errormsg = CTestArrayHelper::get(error_get_last(), 'message');
$response = false;
}
if ($response !== false) {