<?php
$file = file('/var/www/site.ru/data/logs/site.ru.error.log');
foreach($file as $string){
if(mb_stripos($string, 'Nemesida') !== false){
echo 'Needle string : ', $string, '<br>';
$re = '/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/';
preg_match($re, $string, $ip);
$client = $ip[1];
echo 'client: ', $client, '<hr>';
}
}
$fp = fopen('/path/to/log/file', 'r');
while (true) {
$line = fgets($fp);
if ($line === false) {
echo "no new content, sleeping\n";
sleep(3);
fseek($fp, 0, SEEK_CUR);
} else {
echo $line;
}
}
<?php
$json = '[{"id":"00000008524","title":"Комплекс из двух исследований \"МРТ головного мозга и гипофиза\" (Комплексное МРТ головного мозга с программой ранней диагностики инсультов и МР ангиография, Комплексное МРТ гипофиза)","prefix":"","type":"online","price":330.46,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":3600},{"id":"00000008520","title":"Комплекс из двух исследований \"МРТ головного мозга и шейного отдела позвоночника\" (Комплексное МРТ головного мозга с программой ранней диагностики инсультов и МР ангиография, Комплексное МРТ шейного отдела позвоночника и спинного мозга)","prefix":"","type":"offline","price":332.29,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":3900},{"id":"00000008522","title":"Комплекс из двух исследований \"МРТ грудного и поясничного отделов позвоночника\" (Комплексное МРТ грудного отдела позвоночника и спинного мозга, Комплексное МРТ поясничного и крестцового отдела позвоночника и спинного мозга)","prefix":"","type":"online","price":253.54,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":3900},{"id":"00000008526","title":"Комплекс из двух исследований \"МРТ обоих плечевых суставов\" (Комплексное МРТ плечевого сустава, Комплексное МРТ плечевого сустава)","prefix":"","type":"offline","price":350.22,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":4800},{"id":"00000008523","title":"Комплекс из двух исследований \"МРТ поясничного отдела позвоночника, крестца и копчика\" (Комплексное МРТ поясничного и крестцового отдела позвоночника и спинного мозга, Комплексное МРТ крестца и копчика)","prefix":"","type":"online","price":301.84,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":3900},{"id":"00000008521","title":"Комплекс из двух исследований \"МРТ шейного и грудного отделов позвоночника\" (Комплексное МРТ шейного отдела позвоночника и спинного мозга, Комплексное МРТ грудного отдела позвоночника и спинного мозга)","prefix":"","type":"offline","price":268.02,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":4200},{"id":"00000008528","title":"Комплекс из двух исследований \"МРТ шейного отдела позвоночника и плечевого сустава\" (Комплексное МРТ шейного отдела позвоночника и спинного мозга, Комплексное МРТ плечевого сустава)","prefix":"","type":"online","price":329.32,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":4500},{"id":"00000007924","title":"комплексное МРТ гипофиза","prefix":"","type":"offline","price":157.57,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":1800},{"id":"00000007738","title":"комплексное МРТ головного мозга с программой ранней диагностики инсультов и МР ангиография","prefix":"","type":"online","price":182.70,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":1800},{"id":"00000007741","title":"комплексное МРТ грудного отдела позвоночника и спинного мозга","prefix":"","type":"online","price":118.44,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":2100},{"id":"00000007735","title":"комплексное МРТ коленного сустава","prefix":"","type":"online","price":163.25,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":2100},{"id":"00000007739","title":"комплексное МРТ крестца и копчика","prefix":"","type":"online","price":166.74,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":2100},{"id":"00000007737","title":"комплексное МРТ крестцово-подвздошных сочленений","prefix":"","type":"online","price":113.94,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":2400},{"id":"00000007730","title":"комплексное МРТ лучезапястного сустава","prefix":"","type":"online","price":184.50,"currency":"BYN","category_id":"00000007142","no_staff":true,"during":2400}]';
echo 'Исходный JSON: ', $json, "<br><br>\r\n\r\n";
$objects_array = json_decode($json);
$new_objects_array = [];
foreach($objects_array as $object){
if($object->type != 'offline'){
$new_objects_array[] = $object;
}
}
$new_json = json_encode($new_objects_array, JSON_UNESCAPED_UNICODE);
echo 'Перебранный JSON: ', $new_json;
<html>
<body>
<button id="btn_send">send</button>
<script>
let data = {
city: "Gorod",
prim: "Примечание"
}
btn_send.addEventListener('click',async() => {
console.log('dd');
//отправляем данные методом POST
let response = await fetch('web_tp_word.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(data)
});
let result = await response.json();
console.log(result);
});
</script>
</body>
</html>
<?php
$str = file_get_contents('php://input');
$input_json = json_decode($str, true);
$response = [
'request' => $input_json,
'test' => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'test 2' => 'bla-bla-bla'
];
echo json_encode($response, JSON_UNESCAPED_UNICODE);
После передачи клиенту cookie станут доступны через массив $_COOKIE при следующей загрузке страницы. Значения cookie также есть в $_REQUEST.
echo json_encode(
[
"res" => $arParams["~AUTH_RESULT"],
]
);
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<script>
var result = axios.post('app.php?forgot_password=yes', JSON.stringify({
AUTH_FORM: "Y",
TYPE: "SEND_PWD",
USER_EMAIL: 'email',
USER_LOGIN: 'login',
send_account_info: "Send",
ChangeLk: 'Y',
})).then(function (response) {
console.log(response.data.res);
}).catch(function (error) {
console.log(error);
});
</script>
</body>
</html>
<?php
echo json_encode(
[
"res" => 'Something',
]
);
<?php
namespace PHPCadesSOAP;
use CPStore;
class CryptoPro {
public static function SetupStore($location, $name, $mode) {
$store = new CPStore();
$store->Open($location, $name, $mode);
return $store;
}
public static function SetupCertificates($location, $name, $mode) {
$store = self::SetupStore($location, $name, $mode);
return $store->get_Certificates();
}
public static function SetupCertificate($location, $name, $mode, $find_type, $query, $valid_only, $number) {
$certs = self::SetupCertificates($location, $name, $mode);
if ($find_type != NULL) {
$certs = $certs->Find($find_type, $query, $valid_only);
if (is_string($certs))
return $certs;
else
return $certs->Item($number);
}
else {
$cert = $certs->Item($number);
return $cert;
}
}
public static function createMessageID() {
$uuid = md5(uniqid(rand(), true));
$guid = 'uudi:' .
substr($uuid, 0, 8) . "-" .
substr($uuid, 8, 4) . "-" .
substr($uuid, 12, 4) . "-" .
substr($uuid, 16, 4) . "-" .
substr($uuid, 20, 12);
return $guid;
}
}
<?php
namespace PHPCadesSOAP;
use SoapClient;
use PHPCadesSOAP\Logger;
use DOMDocument;
use PHPCadesSOAP\CryptoPro;
use CPSigner;
use CPSignedXml;
class MySoapClient extends SoapClient {
private $certSubjectName = 'test certificate';
private $IPS_id = '********-****-****-****-************';
function __doRequest($request, $location, $saction, $version, $one_way = NULL) {
Logger::debug('Неподписанный запрос от MySoapClient - ' . $request);
$cert = CryptoPro::SetupCertificate(CURRENT_USER_STORE, "My", STORE_OPEN_READ_ONLY, CERTIFICATE_FIND_SUBJECT_NAME, $this->certSubjectName, 0, 1);
$certData = preg_replace('/\n+/', '', $cert->export(0));
$xml = new DOMDocument();
$xml->loadXML($request);
$Envelope = $xml->getElementsByTagName('Envelope')->item(0);
$Body = $Envelope->getElementsByTagName('Body')->item(0);
$prefix = $Envelope->prefix;
$Envelope->setAttribute('xmlns:wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd');
$Envelope->setAttribute('xmlns:wsu', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd');
$Envelope->setAttribute('xmlns:ds', 'http://www.w3.org/2000/09/xmldsig#');
$Envelope->setAttribute('xmlns:a', 'http://www.w3.org/2005/08/addressing');
$Header = $xml->createElement($prefix . ':Header');
$To = $xml->createElement('a:To', 'https://**********************');
$Action = $xml->createElement('a:Action', 'sendResponse');
$ReplyTo = $xml->createElement('a:ReplyTo');
$ReplyToAddress = $xml->createElement('a:Address', 'http://www.w3.org/2005/08/addressing/anonymous');
$FaultTo = $xml->createElement('a:FaultTo');
$FaultToAddress = $xml->createElement('a:Address', 'http://www.w3.org/2005/08/addressing/anonymous');
$MessageID = $xml->createElement('a:MessageID', CryptoPro::createMessageID());
$Security = $xml->createElement('wsse:Security');
$BinarySecurityToken = $xml->createElement('wsse:BinarySecurityToken', $certData);
$BinarySecurityToken->setAttribute('EncodingType', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary');
$BinarySecurityToken->setAttribute('ValueType', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3');
$bsd_id = uniqid('x509-');
$BinarySecurityToken->setAttribute('wsu:Id', $bsd_id);
$Signature = $xml->createElement('ds:Signature');
$SignedInfo = $xml->createElement('ds:SignedInfo');
$CanonicalizationMethod = $xml->createElement('ds:CanonicalizationMethod');
$CanonicalizationMethod->setAttribute('Algorithm', 'http://www.w3.org/2001/10/xml-exc-c14n#');
$SignatureMethod = $xml->createElement('ds:SignatureMethod');
$SignatureMethod->setAttribute('Algorithm', 'urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-256');
$Reference_of_body = $xml->createElement('ds:Reference');
$uri_on_body = uniqid('body-');
$Reference_of_body->setAttribute('URI', '#' . $uri_on_body);
$Body->setAttribute('wsu:Id', $uri_on_body);
$Reference_of_body_Transforms = $xml->createElement('ds:Transforms');
$Reference_of_body_Transforms_Transform = $xml->createElement('ds:Transform');
$Reference_of_body_Transforms_Transform->setAttribute('Algorithm', 'http://www.w3.org/2001/10/xml-exc-c14n#');
$Reference_of_body_DigestMethod = $xml->createElement('ds:DigestMethod');
$Reference_of_body_DigestMethod->setAttribute('Algorithm', 'urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256');
$Reference_of_body_DigestValue = $xml->createElement('ds:DigestValue');
$SignatureValue = $xml->createElement('ds:SignatureValue');
$KeyInfo = $xml->createElement('ds:KeyInfo');
$SecurityTokenReference = $xml->createElement('wsse:SecurityTokenReference');
$SecurityTokenReference_Reference = $xml->createElement('wsse:Reference');
$SecurityTokenReference_Reference->setAttribute('ValueType', "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3");
$SecurityTokenReference_Reference->setAttribute('URI', '#' . $bsd_id);
$Envelope->insertBefore($Header, $Body);
$Header->appendChild($To);
$Header->appendChild($Action);
$Header->appendChild($ReplyTo);
$ReplyTo->appendChild($ReplyToAddress);
$Header->appendChild($FaultTo);
$FaultTo->appendChild($FaultToAddress);
$Header->appendChild($MessageID);
$Header->appendChild($Security);
$Security->appendChild($BinarySecurityToken);
$Security->appendChild($Signature);
$Signature->appendChild($SignedInfo);
$SignedInfo->appendChild($CanonicalizationMethod);
$SignedInfo->appendChild($SignatureMethod);
$SignedInfo->appendChild($Reference_of_body);
$Reference_of_body->appendChild($Reference_of_body_Transforms);
$Reference_of_body_Transforms->appendChild($Reference_of_body_Transforms_Transform);
$Reference_of_body->appendChild($Reference_of_body_DigestMethod);
$Reference_of_body->appendChild($Reference_of_body_DigestValue);
$Signature->appendChild($SignatureValue);
$Signature->appendChild($KeyInfo);
$KeyInfo->appendChild($SecurityTokenReference);
$SecurityTokenReference->appendChild($SecurityTokenReference_Reference);
$request = $xml->saveXML();
$signer = new CPSigner();
$signer->set_Certificate($cert);
$signer->set_Options(2);
$sd = new CPSignedXml();
$sd->set_SignatureType(2);
$sd->set_Content($request);
$sd->set_DigestMethod('urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-512');
$sd->set_SignatureMethod('urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-512');
$signedXml = $sd->Sign($signer, "//*[local-name()='Signature']");
Logger::debug('подписанный запрос от MySoapClient - ' . $signedXml);
return parent::__doRequest($signedXml, $location, $saction, $version);
}
}
<?php
$xml = file_get_contents('/var/www/dsig.xml');
try {
$xpath = "//*[local-name()='Signature' and namespace-uri()='http://www.w3.org/2000/09/xmldsig#']";
$xmldsig = new CPSignedXML();
$xmldsig->Verify($xml, $xpath);
print("OK\n");
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
function prints ($word){
echo $word;
}
return array($x1,$x2);
в equation()
возвращает массив, а в prints()
ты пытаешься вывести массив через echo как строку без преобразования. Не надо так делать. Убрал твой говнокод prints()
и случилась магия! return array($x1,$x2);
Работает!<?php
$a= 1;
$b= -2;
$c= -3;
function equation ($a,$b,$c){
$D=pow($b,2)-4*$a*$c;//D=b^2-4ac
if ($D > 0) {// если D>0
$x1=(-$b+sqrt($D))/(2*$a);// Первый X
$x2=(-$b-sqrt($D))/(2*$a);// Второй X
}elseif ($D = 0) {
$x1=(-$b+sqrt($D))/(2*$a);// Первый X
}elseif ($D < 0){
$x1='Нет решения';
}
return [$x1, $x2];
}
$math = equation ($a,$b,$c);
print_r($math);