- 1
- 2
- 3
- 4
function fDim($m){
$vDim = array(1, 3, 5, 7, 8, 10, 12);
return (in_array($m, $vDim) ? 31 : ($m == 2? 28 : 30));
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+158.1
function fDim($m){
$vDim = array(1, 3, 5, 7, 8, 10, 12);
return (in_array($m, $vDim) ? 31 : ($m == 2? 28 : 30));
}
Функция возвращает количество дней в месяце. Очень забавный пассаж, ага?
+154
if ( isset( $criterias['name'] ) && ($criterias['name'] = trim( $criterias['name'] )) )
{
$conditions .= empty( $conditions ) ? '(' : ' AND ';
$conditions .= "name LIKE '%".addslashes( $criterias['name'] )."%'";
}
if ( isset( $criterias['address'] ) && ($criterias['address'] = trim( $criterias['address'] )) )
{
$conditions .= empty( $conditions ) ? '(' : ' AND ';
$conditions .= "address LIKE '%".addslashes( $criterias['address'] )."%'";
}
// если условие непустое, то закрываем скобку
$conditions .= empty( $conditions ) ? '' : ')';
Вместо использования массива для условий и последующего его объединения
+157.1
return strtoupper(strtr($str, "йцукенгшщзхъэждлорпавыфячсмитьбюё", "ЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮЁ"));
1C-Bitrix, вот говнищще-то!
+129.4
(string) $def == (string) $value
Видимо о том, что == сравнивает строковые представления программист не знал.
+131.3
function key_check($key) {
if ($key == '') { return ''; }
$key = preg_replace("/[^\w\xB2-\xB4\xBF-\xFF\xA5\xA8\xAA\xAF\xB8\xBA\s]/", "", $key );
if ($key =='_SERVER' OR $key =='_SESSION' OR $key =='_FILES' OR $key =='_REQUEST' OR $key =='GLOBALS') die("<h3>Error variable ".basename(__FILE__)." ".__LINE__."</h3>");
else return $key;
}
function str_check($str_val) {
if ($str_val == '') { return ''; }
if(preg_match("/<[^>]*script*\"?[^>]*>/i", $str_val)
or preg_match("/<[^>]*object*\"?[^>]*>/i", $str_val)
or preg_match("/<[^>]*applet*\"?[^>]*>/i", $str_val)
or preg_match("/<[^>]*form*\"?[^>]*>/i" , $str_val)
or preg_match("/&#\d+;{0,1}/i" , $str_val) ){
die("<h3>ERROR ".basename(__FILE__)." ".__LINE__."</h3>");
}
$str_val = str_replace( "&" , '&' , $str_val );
$str_val = str_replace( "<!--" , '<!--' , $str_val );
$str_val = str_replace( "-->" , '-->' , $str_val );
$str_val = str_replace( ">" , '>' , $str_val );
$str_val = str_replace( "<" , '<' , $str_val );
$str_val = str_replace( "\"" , '"' , $str_val );
$str_val = str_replace( "\r" , null , $str_val );
$str_val = str_notsqlatacs($str_val);
if (!get_magic_quotes_gpc()){$str_val=addslashes($str_val);}
return $str_val;
}
function str_notsqlatacs($str_val) {
$searcharray =array('/drop/i','/delete/i','/union/i','/char/i','/benchmark/i','/expression/i','/alert/i','/replace/i','/write/i','/document/i','/window/i','/script/i','/user_pass/i','/unescape/i','/eval/i','/form/i','/applet/i','/object/i','/user_login/i','/setTimeout/i','/onerror/i');
$replacearray=array('drop','delete','union','char','benchmark','Expression','Alert','Replace','Write','Document','Window','Script','User_pass','Unescape','Eval','Form','Applet','Object','User_login','/SetTimeout/i','/Onerror/i');//
$str_val=preg_replace($searcharray, $replacearray, $str_val);
return $str_val;
}
Фрагмент файла ./php/wojs.php "портального движка" WebCodePortalSystem версии 5.2. И вот так вся CMSка - два с половиной мегабайта говна.
+158.4
<?php
//...
if (!count($error)) {
if(strpos($msg,'samp.ucoz')) $msg = htmlSpecialChars('>>>>>>>>>>>{ Я ДАЛБОЁБ }<<<<<<<<<<<<<');
if(strpos(strtoupper($msg),'GAMES.SHOP777')) $msg = htmlSpecialChars('>>>>>>>>>>>{ Я ДАЛБОЁБ }<<<<<<<<<<<<<');
$DB->query("INSERT INTO `guestbook` (`user_id`,`user_name`,`msg`,`add_date`,`ip`) VALUES ('$user_id','$user_name','$msg',NOW(),'$ip')");
header("Location: guestbook.php"); exit;
}
//...
?>
Защита от спама :))
Не, ну а чё, задолбали!
+142.5
$out="<table valign=top>";
for($k = 0; $k <= 6; $k += 1){
$sql="SELECT * FROM user_news1 ORDER BY date DESC LIMIT ".$k.",1";
$query=mysql_query($sql);
$out.="<tr>";
while ($res=mysql_fetch_assoc($query)){
$out.="<td style='vertical-align:top'>
<div class=newsblock>
<div class=newsdate>".date("d.m.Y G:i",strtotime($res['date']))."</div>
<div class=newschapter><a href='/news/".$res['id'].".html'>".$res['header']."</a></div>
".($res['photo']!= '' ? " <a href='/news/".$res['id']."'><img src=/".str_replace(".", "_small.", $res['photo'])." class=imgnews border=0 align=left></a> " : "")."
<div>".$res['announce']."</div></td>";
}
$out.="</tr>";
}
$out.="</table>";
echo $out;
Вот как надо новости выводить:)
+151.4
if (isset($_SESSION) && !is_array($_SESSION)){
exit("Hacking attempt");
}
просто улыбнуло
симпатичная антихакерская защита
+136.8
function lock_user($id)
{
global $db_obj;
$SQL = "SELECT GET_LOCK('%s', 10)";
$SQL = sprintf($SQL, (int)$id);
$result = $db_obj->query($SQL);
$row = $db_obj->fetch_array($result);
$key = "GET_LOCK('" . (int)($id) . "', 10)";
$res = $row[$key];
return $res;
}
дзен
+135.1
// Validate numeric field
public function validateNumber($field, $errorMessage, $min=2, $max=32){
if(!isset($_REQUEST[$field]) || !is_numeric($_REQUEST[$field])
|| strlen($_REQUEST[$field])<$min
|| strlen($_REQUEST[$field])>$max)
{
$this->errors[]=str_replace('<br>', '', $errorMessage) . '<br>';
}
}
Legacy код от индусов. Строки 4-5 просто лучшие.