-
+168
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
<?php
function isValidCharacters($str)
{
$str2 = preg_replace("[^a-zA-Zа-яА-Я[email protected]]","",$str);
if ($str != $str2) return FALSE;
return TRUE;
}
$nik=preg_replace("[^a-zA-Zа-яА-Я[email protected]]","",$_POST['nik']);
$pass=preg_replace("[^a-zA-Zа-яА-Я[email protected]]","",$_POST['pass']);
if (!isValidCharacters($nik) || !isValidCharacters($pass))
{
$_SESSION['auth']="error";
$_SESSION['error_mes']="Неверный логин или пароль";
header('Location: ./index.php');
exit();
}
//дальше проверка на совпадение логина\пароля, ничего интересного.
?>
Строка 10, после 8-9, типа "А вдруг?!"
mr.The,
14 Сентября 2011
-
+160
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
function Hehe ($s) {
$str = $s;
$str = preg_replace ("/\\\/","", $str);
$str = preg_replace ("/'/","'", $str);
$str = preg_replace ("/\n/","<br>", $str);
$str = preg_replace ("/\r/","", $str);
return $str;
}
Название функции оригинальное. Лежала в модуле ~5k строк.
Enjoy,
14 Сентября 2011
-
+161
- 1
- 2
- 3
- 4
- 5
$name = $data->fields["name"];
$name = str_replace("\n","",$name);
$name = str_replace("\r","",$name);
$name = str_replace("\\","\\\\",$name);
$name = preg_replace("/'/","'",str_replace("\n","",str_replace("\"",""",$name)));
2, 3 и 4 строчки похожи на серию ударов по мозгу, а последняя на кровавое комбо :)
Enjoy,
14 Сентября 2011
-
+93
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
<%if(myaccount.getCountry().equals( "AF" )){%> <font color="grey"><label for="country">Afghanistan</label></font>
<%}else if(myaccount.getCountry().equals( "AL" )){%> <font color="grey"><label for="country">Albania</label></font>
<%}else if(myaccount.getCountry().equals( "DZ" )){%> <font color="grey"><label for="country">Algeria</label></font>
<%}else if(myaccount.getCountry().equals( "AS" )){%> <font color="grey"><label for="country">American Samoa</label></font>
<%}else if(myaccount.getCountry().equals( "AD" )){%> <font color="grey"><label for="country">Andorra</label></font>
<%}else if(myaccount.getCountry().equals( "AO" )){%> <font color="grey"><label for="country">Angola</label></font>
<%}else if(myaccount.getCountry().equals( "AI" )){%> <font color="grey"><label for="country">Anguilla</label></font>
<%}else if(myaccount.getCountry().equals( "AQ" )){%> <font color="grey"><label for="country">Antarctica</label></font>
<%}else if(myaccount.getCountry().equals( "AG" )){%> <font color="grey"><label for="country">Antigua and Barbuda</label></font>
<%}else if(myaccount.getCountry().equals( "AR" )){%> <font color="grey"><label for="country">Argentina</label></font>
<%}else if(myaccount.getCountry().equals( "AM" )){%> <font color="grey"><label for="country">Armenia</label></font>
<%}else if(myaccount.getCountry().equals( "AW" )){%> <font color="grey"><label for="country">Aruba</label></font>
<%}else if(myaccount.getCountry().equals( "AU" )){%> <font color="grey"><label for="country">Australia</label></font>
<%}else if(myaccount.getCountry().equals( "AT" )){%> <font color="grey"><label for="country">Austria</label></font>
<%}else if(myaccount.getCountry().equals( "AZ" )){%> <font color="grey"><label for="country">Azerbaijan</label></font>
<%}else if(myaccount.getCountry().equals( "BS" )){%> <font color="grey"><label for="country">Bahamas</label></font>
<%}else if ...
Индусская проверка принадлежности аккаунта к определённой стране...
P.S. Всё не влезло - стран у нас много =)
vetal,
14 Сентября 2011
-
+40
- 1
- 2
- 3
- 4
function del_reiting_type($typeid){
global $typeid;
.....
}
как-то так...
brainstorm,
14 Сентября 2011
-
+168
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
foreach ($_POST as $k=>$v)
if (!is_array($v))
$_POST[$k] = htmlspecialchars($v);
else
foreach ($v as $kk=>$vv)
if (!is_array($vv))
$_POST[$k][$kk] = htmlspecialchars($vv);
else
foreach ($vv as $kkk=>$vvv)
if (!is_array($vvv))
$_POST[$k][$kk][$kkk] = htmlspecialchars($vvv);
atarix12,
14 Сентября 2011
-
+162
- 1
- 2
- 3
- 4
- 5
void IniRead(UnicodeString Name, int n)
{
TStringList* lst=new TStringList;
Ini->WriteString("CardNames","Card"+(UnicodeString)n,Name);
}
чувак создал переменную lst просто так, для теплоты душевной. ну хотелось ему чтоб создался stringlist!
phys-tech,
14 Сентября 2011
-
−96
- 1
- 2
- 3
- 4
- 5
- 6
<%products = Array.new
count = Product.count(:conditions => "novelty = 'true'")
while products.size < 10 do
products << Product.find(:first, :conditions => "novelty = 'true'",:offset => rand(count))
products.uniq!
end-%>
при количестве новинок меньше 10 получаем бесконечный цикл. счастье в продакшене, там sql запросы не пишутся в лог)
malleus,
13 Сентября 2011
-
+157
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
<?
/**
* @author i3ookMAn
* @copyright 2011
*/
$H = "H";
$e = "e";
$l = "l";
$o = "o";
$k = ",";
$w = "W";
$r = "r";
$d = "d";
$v = "!";
$kolat = "$H$e$l$l$o$k $w$o$r$l$d$v";
$init = htmlentities($kolat);
function unperekoder($string)
{
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
$lolwto = get_html_translation_table(HTML_ENTITIES);
$lolwto = array_flip($lolwto);
return strtr($string, $lolwto);
}
$exit = unperekoder($init);
echo $exit;
?>
Выводит "Hello, World!" :D
i3ookMAn,
13 Сентября 2011
-
+964
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
using System;
using System.Reflection;
using System.Reflection.Emit;
namespace DynUnloop
{ // Суммирование в цикле
class SumLooping
{ public int Summ(int valMax)
{ int result = 0;
for (int i = 0; i <= valMax; i++)
result += i;
return result;
}
}
// Плоское суммирование
class SumFlat
{ interface ISumCode
{ int ComputeSumm(int valMax);
}
void WriteCode(int valMax)
{ AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "SumFlatAssembly";
AssemblyBuilder assemblyBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(
assemblyName, AssemblyBuilderAccess.Run);
ModuleBuilder moduleBuilder =
assemblyBuilder.DefineDynamicModule("SumFlatModule");
TypeBuilder typeBuilder =
moduleBuilder.DefineType("SumFlatClass"
, TypeAttributes.Public);
typeBuilder.AddInterfaceImplementation(typeof(ISumCode));
/// Задаём возвращаемое зачение и параметр
Type[] paramTypes = { typeof(int) };
Type returnType = typeof(int);
MethodBuilder methodBuilder =
typeBuilder.DefineMethod("ComputeSumm"
, MethodAttributes.Public
| MethodAttributes.Virtual
, returnType, paramTypes);
ILGenerator il = methodBuilder.GetILGenerator();
// Генерируем плоский код.
il.Emit(OpCodes.Ldc_I4, 0);
for (int i = 1; i <= valMax; i++)
{ il.Emit(OpCodes.Ldc_I4, i);
il.Emit(OpCodes.Add);
}
il.Emit(OpCodes.Ret);
// Перекрываем метод ComputeSumm и создаём тип SumFlatClass.
MethodInfo methodInfo =
typeof(ISumCode).GetMethod("ComputeSumm");
typeBuilder.DefineMethodOverride(methodBuilder, methodInfo);
typeBuilder.CreateType();
/// Код готов, создаём объект и берем его интерфейс.
code = (ISumCode)assemblyBuilder.CreateInstance("SumFlatClass");
}
public int Summ(int val)
{ if (this.code == null)
WriteCode(val);
return this.code.ComputeSumm(val);
}
ISumCode code;
}
Оригинальный стиль кода и комментарии сохранёны. (с), или как там.
В коде - разворачивание цикла в "плоский" IL код, который, как доказывается должен выигрывать по производительности.
Elvenfighter,
13 Сентября 2011