- 1
С днём программиста, питухи!
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
С днём программиста, питухи!
И курицы.
+1
/**
* @param string $login
* @return User
* @throws GuzzleException
*/
public function getExternalUser(string $login):FreeIpaUser{
return $this->UserFactory->createUser($login,$this->getUser($login));
}
−1
За "PHP".
0
function IntToDate2($x) {
$dd = $x*1;
$dd_Y = floor($dd/10000);
$dd_M = floor(($dd-($dd_Y*10000))/100);
$dd_D = $dd-($dd_Y*10000)-($dd_M*100);
if ($dd_M<10) $dd_M = "0".$dd_M;
if ($dd_D<10) $dd_D = "0".$dd_D;
$res = $dd_D.".".$dd_M.".".$dd_Y;
if ($dd == 0) $res = "";
return $res;
}
function IntToDate($x) {
$year = substr( $x, 0, 4 );
$month = substr( $x, 4, 2 );
$day = substr( $x, 6, 2 );
return $x == 0 ? '' : "$day.$month.$year";
}
function DateToInt2($x) {
$dd = explode(".",$x);
if (count($dd)>2) {
$dd = $dd[0]*1+$dd[1]*100+$dd[2]*10000;
} else {
$dd = 0;
}
return $dd;
}
function DateToInt($x)
{
$dd = explode('.',$x);
if (count($dd)>2)
$result = $dd[2].$dd[1].$dd[0];
else
$result = 0;
return $result ;
}
function StrDate($x) {
global $MM_Name2;
$dd = $x*1;
$dd_Y = floor($dd/10000);
$dd_M = floor(($dd-($dd_Y*10000))/100);
$dd_D = $dd-($dd_Y*10000)-($dd_M*100);
if ($dd_D<10) $dd_D = "0".$dd_D;
return $dd_D." ".$MM_Name2[$dd_M]." ".$dd_Y;
}
function StrMonth($x) {
global $MM_Name;
$dd = $x*1;
$dd_Y = floor($dd/10000);
$dd_M = floor(($dd-($dd_Y*10000))/100);
$dd_D = $dd-($dd_Y*10000)-($dd_M*100);
if ($dd_D<10) $dd_D = "0".$dd_D;
return $MM_Name[$dd_M]." ".$dd_Y;
}
$theday = mktime (0,0,0,date("m") ,date("d") ,date("Y"));
$today_0=date("d.m.Y",$theday);
$today_1=date("d.m.Y",$theday+(1*86400));
$today_7=date("d.m.Y",$theday+(7*86400));
0
$URL1 = "db_edit.php?db=$db&field=$field&id=".$row['ID']."&setchbx=0&value=";
$URL2 = "db_edit.php?db=$db&field=$field&id=".$row['ID']."&setchbx=1&value=";
$Name1 = $Name."_0_".$row['ID'];
$Name2 = $Name."_1_".$row['ID'];
$NamePP = $Name."_pp_".$row['ID'];
$values = $row[$field];
if ($values=="") $values ="0|";
$values = explode("|",$values);
$numval = count($values)-1;
$lastval = $values[$numval];
if ($lastval=="") $lastval = "##";
$lastval = explode("#",$lastval);
$val = $lastval[2];
$sval = $val;
if ($val=="") $sval = "---";
if ($val=="") $val = $today_0;
$dvv = $val;
$val = explode(".",$val);
$bgcl = "#fff";
$bcl = "#fff";
if ($lastval[2]=="") {
$bgcl = "#fff";
$bcl = "#fff";
} else {
if (DateToInt($today_7)>DateToInt($lastval[2])) $bgcl = "#fee";
if (DateToInt($today_7)>DateToInt($lastval[2])) $bcl = "#f44";
if (DateToInt($today_1)>DateToInt($lastval[2])) $bgcl = "#faa";
if (DateToInt($today_1)>DateToInt($lastval[2])) $bcl = "#f44";
if (DateToInt($today_0)>DateToInt($lastval[2])) $bgcl = "#f44";
if (DateToInt($today_0)>DateToInt($lastval[2])) $bcl = "#f44";
}
if ($values[0]=="1") {
$bgcl = "#afa";
$bcl = "#afa";
}
0
public function validate($mailAddress)
{
$this->mailAddress = $mailAddress;
if($this->validateMailAddress()) {
if ($this->checkMXRecord()) {
throw new \Exception('Mail is valid');
}
}
throw new \Exception('Mail is invalid');
}
+1
$ss_n = 0;
$ss_nf = 0;
$ss_f = 0;
$ss_n_pl = 0;
$ss_nf_pl = 0;
$ss_f_pl = 0;
$ids_count = count($ids);
for ($i=0;$i < $ids_count;$i++) {
$key = $w_dates[$z]."|1|".$ids[$i];
$ss_n += $w_n_s[$key]*1;
$ss_nf += $w_nf_s[$key]*1;
$ss_f += $w_f_s[$key]*1;
$key = $w_dates[$z]."|2|".$ids[$i];
$ss_n += $w_n_s[$key]*1;
$ss_nf += $w_nf_s[$key]*1;
$ss_f += $w_f_s[$key]*1;
$key = $w_dates[$z]."|3|".$ids[$i];
$ss_n += $w_n_s[$key]*1;
$ss_nf += $w_nf_s[$key]*1;
$ss_f += $w_f_s[$key]*1;
}
$ids_count = count($ids);
for ($i=0;$i < $ids_count;$i++) {
$key = $w_dates[$z]."|1|".$ids[$i];
$ss_n_pl = $ss_n_pl + $w_n_s_pl[$key]*1;
$ss_nf_pl = $ss_nf_pl + $w_nf_s_pl[$key]*1;
$ss_f_pl = $ss_f_pl + $w_f_s_pl[$key]*1;
$key = $w_dates[$z]."|2|".$ids[$i];
$ss_n_pl = $ss_n_pl + $w_n_s_pl[$key]*1;
$ss_nf_pl = $ss_nf_pl + $w_nf_s_pl[$key]*1;
$ss_f_pl = $ss_f_pl + $w_f_s_pl[$key]*1;
$key = $w_dates[$z]."|3|".$ids[$i];
$ss_n_pl = $ss_n_pl + $w_n_s_pl[$key]*1;
$ss_nf_pl = $ss_nf_pl + $w_nf_s_pl[$key]*1;
$ss_f_pl = $ss_f_pl + $w_f_s_pl[$key]*1;
}
echo "<td class='Field' rowspan='3' style='vertical-align: middle;'><b>".OutNF($ss_n,$ss_nf,$ss_f)."</b></td>\n";
echo "<td class='Field' rowspan='3' style='vertical-align: middle;'><b style='color:#aa0000;'>".OutNF($ss_n_pl,$ss_nf_pl,$ss_f_pl)."</b></td>\n";
echo "</tr><tr>";
////////////////////////////////////////////////////////////
echo "<td class='Field' width='40' style='vertical-align: middle;'><b>II</b></td>\n";
$s_n = 0;
$s_nf = 0;
$s_f = 0;
$s_n_pl = 0;
$s_nf_pl = 0;
$s_f_pl = 0;
for ($i=0;$i < count($ids);$i++) {
$key = $w_dates[$z]."|2|".$ids[$i];
$s_n = $s_n + $w_n_s[$key]*1;
$s_nf = $s_nf + $w_nf_s[$key]*1;
$s_f = $s_f + $w_f_s[$key]*1;
$s_n_pl = $s_n_pl + $w_n_s_pl[$key]*1;
$s_nf_pl = $s_nf_pl + $w_nf_s_pl[$key]*1;
$s_f_pl = $s_f_pl + $w_f_s_pl[$key]*1;
if ($edti_stat[$key]==1){
echo "<td class='Field'>".OutNF($w_n_s[$key],$w_nf_s[$key],$w_f_s[$key])."</td>\n";
}
if ($edti_stat[$key]==0){
$link_dat = explode("|", $key);
$link_dat2 = $link_dat[0];
$link_dat3 = $link_dat[1];
echo "<td class='Field'><a target='_bland' href='index.php?do=show&formid=64&p0=".$link_dat2."&p1=".$link_dat3."'><b style='color:#aa0000;'>".OutNF($w_n_s_pl[$key],$w_nf_s_pl[$key],$w_f_s_pl[$key])."</b></a></td>\n";
}
}
echo "<td class='Field'></td>\n";
echo "<td class='Field'><b>".OutNF($s_n,$s_nf,$s_f)."</b></td>\n";
echo "<td class='Field'></td>\n";
echo "<td class='Field'></td>\n";
echo "<td class='Field'><b style='color:#aa0000;'>".OutNF($s_n_pl,$s_nf_pl,$s_f_pl)."</b></td>\n";
echo "<td class='Field'></td>\n";
////////////////////////////////////////////////////////////
0
if ($arr_tbl_1[$key_1] !== $cur_vid){
$cur_vid_key = $key_1;
$cur_vid_w = $arr_tbl_1[$key_1];
$cur_v_ind = $cur_v_ind + 1;
while ($arr_tbl_1[$cur_vid_key] == $cur_vid_w){
$sum_cur_v_6 += (float)$arr_tbl_6[$cur_vid_key];
$sum_cur_v_7 += (float)$arr_tbl_7[$cur_vid_key];
$sum_cur_v_10 += (float)$arr_tbl_10[$cur_vid_key];
$cur_vid_key += 1;
}
if ($sum_cur_v_6==0) { $sum_cur_v_6_0 = 1;}else{ $sum_cur_v_6_0 = $sum_cur_v_6;}
if ($sum_cur_v_7==0) { $sum_cur_v_7_0 = 1;}else{ $sum_cur_v_7_0 = $sum_cur_v_7;}
if (strlen(substr(strstr($sum_cur_v_6, "."), 1))==0) { $tbl_1_6 = $sum_cur_v_6.".00";}
if (strlen(substr(strstr($sum_cur_v_6, "."), 1))==1) { $tbl_1_6 = $sum_cur_v_6."0";}
if (strlen(substr(strstr($sum_cur_v_6, "."), 1))==2) { $tbl_1_6 = $sum_cur_v_6;}
if (strlen(substr(strstr($sum_cur_v_6, "."), 1))>2) { $tbl_1_6 = number_format($sum_cur_v_6, 2, '.', '');}
if (strlen(substr(strstr($sum_cur_v_7, "."), 1))==0) { $tbl_1_7 = $sum_cur_v_7.".00";}
if (strlen(substr(strstr($sum_cur_v_7, "."), 1))==1) { $tbl_1_7 = $sum_cur_v_7."0";}
if (strlen(substr(strstr($sum_cur_v_7, "."), 1))==2) { $tbl_1_7 = $sum_cur_v_7;}
if (strlen(substr(strstr($sum_cur_v_7, "."), 1))>2) { $tbl_1_7 = number_format($sum_cur_v_7, 2, '.', '');}
if (strlen(substr(strstr(($sum_cur_v_6-$sum_cur_v_7), "."), 1))==0) { $tbl_1_8 = ($sum_cur_v_6-$sum_cur_v_7).".00";}
if (strlen(substr(strstr(($sum_cur_v_6-$sum_cur_v_7), "."), 1))==1) { $tbl_1_8 = ($sum_cur_v_6-$sum_cur_v_7)."0";}
if (strlen(substr(strstr(($sum_cur_v_6-$sum_cur_v_7), "."), 1))==2) { $tbl_1_8 = ($sum_cur_v_6-$sum_cur_v_7);}
if (strlen(substr(strstr(($sum_cur_v_6-$sum_cur_v_7), "."), 1))>2) { $tbl_1_8 = number_format(($sum_cur_v_6-$sum_cur_v_7), 2, '.', '');}
if (strlen(substr(strstr(($sum_cur_v_7/$sum_cur_v_6_0*100), "."), 1))==0) { $tbl_1_9 = ($sum_cur_v_7/$sum_cur_v_6_0*100).".00";}
if (strlen(substr(strstr(($sum_cur_v_7/$sum_cur_v_6_0*100), "."), 1))==1) { $tbl_1_9 = ($sum_cur_v_7/$sum_cur_v_6_0*100)."0";}
if (strlen(substr(strstr(($sum_cur_v_7/$sum_cur_v_6_0*100), "."), 1))==2) { $tbl_1_9 = ($sum_cur_v_7/$sum_cur_v_6_0*100);}
if (strlen(substr(strstr(($sum_cur_v_7/$sum_cur_v_6_0*100), "."), 1))>2) { $tbl_1_9 = number_format(($sum_cur_v_7/$sum_cur_v_6_0*100), 2, '.', '');}
if (strlen(substr(strstr($sum_cur_v_10, "."), 1))==0) { $tbl_1_10 = $sum_cur_v_10.".00";}
if (strlen(substr(strstr($sum_cur_v_10, "."), 1))==1) { $tbl_1_10 = $sum_cur_v_10."0";}
if (strlen(substr(strstr($sum_cur_v_10, "."), 1))==2) { $tbl_1_10 = $sum_cur_v_10;}
if (strlen(substr(strstr($sum_cur_v_10, "."), 1))>2) { $tbl_1_10 = number_format($sum_cur_v_10, 2, '.', '');}
if (strlen(substr(strstr(($sum_cur_v_10/$sum_cur_v_7_0), "."), 1))==0) { $tbl_1_11 = ($sum_cur_v_10/$sum_cur_v_7_0).".00";}
if (strlen(substr(strstr(($sum_cur_v_10/$sum_cur_v_7_0), "."), 1))==1) { $tbl_1_11 = ($sum_cur_v_10/$sum_cur_v_7_0)."0";}
if (strlen(substr(strstr(($sum_cur_v_10/$sum_cur_v_7_0), "."), 1))==2) { $tbl_1_11 = ($sum_cur_v_10/$sum_cur_v_7_0);}
if (strlen(substr(strstr(($sum_cur_v_10/$sum_cur_v_7_0), "."), 1))>2) { $tbl_1_11 = number_format(($sum_cur_v_10/$sum_cur_v_7_0), 2, '.', '');}
echo "<tr>
<td class='field' style='background:#CBDEF4;' colspan='5'><b class='not_tr' name='arr_tbl_1_".$cur_v_ind."' style='cursor:pointer; border:1px solid #000; border-radius:6px;' onclick='show_tr_1(this.getAttribute(\"name\"), this.getAttribute(\"class\"), this);'> + </b><b class='not_tr' name='arr_tbl_1_".$cur_v_ind."' style='display:none; cursor:pointer; border:1px solid #000; border-radius:6px;' onclick='show_tr_2(this.getAttribute(\"name\"), this.getAttribute(\"class\"), this);'> - </b> ".$arr_tbl_1[$key_1]."</td>
<td name='max_numb_6' class='field' style='text-align:right; background:#CBDEF4;'>".$tbl_1_6."</td>
<td name='max_numb_7' class='field' style='text-align:right; background:#CBDEF4;'>".$tbl_1_7."</td>
<td name='max_numb_8' class='field' style='text-align:right; background:#CBDEF4;'>".$tbl_1_8."</td>
<td name='max_numb_9' class='field' style='text-align:right; background:#CBDEF4;'>".$tbl_1_9."</td>
<td name='max_numb_10' class='field' style='text-align:right; background:#CBDEF4;'>".$tbl_1_10."</td>
<td name='max_numb_11' class='field' style='text-align:right; background:#CBDEF4;'>".$tbl_1_11."</td>
</tr>";
$itog_sum_6 += $sum_cur_v_6;
$itog_sum_7 += $sum_cur_v_7;
$itog_sum_10 += $sum_cur_v_10;
$tbl_1_6 = "";
$tbl_1_7 = "";
$tbl_1_8 = "";
$tbl_1_9 = "";
$tbl_1_10 = "";
$tbl_1_11 = "";
$sum_cur_v_6 = 0;
$sum_cur_v_7 = 0;
$sum_cur_v_10 = 0;
}
0
$path = str_replace("\\", "/", __FILE__);
$path = substr($path, 0, strlen($path) - strlen("/index.php"));
include($path."/version.php");
официальный гайд битрикса по установке модулей))
https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=101&LESSON_ID=2902
мне литерали плохо уже
0
// Проверка активных ip-адресов
$is_active = false;
if ($dir = opendir($path_active)) {
while (false !== ($filename = readdir($dir))) {
// Выбирается ip + время активации этого ip
if (preg_match('#^(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})_(\d+)$#', $filename, $matches)) {
if ($matches[2] >= time() - self::intervalSeconds) {
if ($matches[1] == $ip_address) {
$times = intval(trim(file_get_contents($path_active . $filename)));
if ($times >= self::intervalTimes - 1) {
touch($path_block . $filename);
unlink($path_active . $filename);
} else {
file_put_contents($path_active . $filename, $times + 1);
}
$is_active = true;
}
} else {
unlink($path_active . $filename);
}
}
}
closedir($dir);
}
// Проверка заблокированных ip-адресов
$is_block = false;
if ($dir = opendir($path_block)) {
while (false !== ($filename = readdir($dir))) {
// Выбирается ip + время блокировки этого ip
if (preg_match('#^(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})_(\d+)$#', $filename, $matches)) {
if ($matches[2] >= time() - self::blockSeconds) {
if ($matches[1] == $ip_address) {
$is_block = true;
$time_block = $matches[2] - (time() - self::blockSeconds) + 1;
}
} else {
unlink($path_block . $filename);
}
}
}
closedir($dir);
}
// ip-адрес заблокирован
if ($is_block) {
header('HTTP/1.0 502 Bad Gateway');
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '<title>502 Bad Gateway</title>';
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
echo '</head>';
echo '<body>';
echo '<h1 style="text-align:center">502 Bad Gateway</h1>';
echo '<p style="background:#ccc;border:solid 1px #aaa;margin:30px au-to;padding:20px;text-align:center;width:700px">';
echo 'К сожалению, Вы временно заблокированы, из-за частого запроса страниц сайта.<br />';
echo 'Вам придется подождать. Через ' . $time_block . ' секунд(ы) Вы будете автоматически разблокированы.';
echo '</p>';
echo '</body>';
echo '</html>';
exit;
}
PHP-скрипт для защиты от DDOS, парсинга и ботов
https://habr.com/ru/post/659811/