Файл: test.otwap.aux.su/lib/functions.php
Строк: 130
<?php
function cook ($log, $pass) {
$log = strtolower (trim($log));
$query = "SELECT count(*) from user where login = "$log" and password = "$pass";";
if ($set = select ($query)) {
$row = mysql_fetch_row ($set);
if ($row[0] > 0) {
$query = "SELECT `id`,`key`,`login` from user where login = "$log" and password = "$pass";";
$set = select ($query);
$row = mysql_fetch_array ($set);
$return[0] = $row[id];
$return[1] = $row[key];
$return[2] = $row[login];
return $return;
}
}
return false;
}
function identification ($login) {
$query = "select login from user where (login = '$login')";
$set = select ($query);
$row = mysql_fetch_array ($set);
if (($row['login'] == $login)) {
return TRUE;
} else {
return false;
}
}
function select ($a) {
if ($link = connect ()) {
if (!($pq=mysql_query ($a, $link))) {
print("Не могу выполнить запрос!");
print(mysql_errno() . ":" . mysql_error());
} else {
return $pq;
}
} else return false;
}
function insert ($query) {
if ($link = connect ()) {
if (!($pq=mysql_query ($query, $link))) {
$alert = false;
} else {
$alert = mysql_insert_id ();
}
} else $alert = false;
return $alert;
}
function updata ($query) {
if ($link = connect ()) {
if (!($pq=mysql_query ($query, $link))) {
$alert = false;
} else {
$alert = true;
}
} else $alert = false;
return $alert;
}
function connect () {
$host = HOST_BD;
$user = USER_BD;
$password_bd = PASSWORD_BD;
$bd_name = NAME_BD;
$link = mysql_connect ($host, $user, $password_bd) or die ("Не могу подключиться к базе данных, обратитесь к
администратору");
if (!$link) return false;
if (!mysql_select_db ($bd_name)) return false;
return $link;
}
function mixer($out, $count) {
if ($out <= $count) {
$i=0;
while ($i<$out) {
$flag = true;
$rand = rand(0, $count-1);
for ($j=0; $j<$i; $j++) {
if ($rand == $array[$j]) $flag = false;
}
if ($flag) {
$array[$i] = $rand;
$i++;
}
}
} else {
while ($i<$count) {
$flag = true;
$rand = rand(0, $count-1);
for ($j=0; $j<$i; $j++) {
if ($rand == $array[$j]) $flag = false;
}
if ($flag) {
$array[$i] = $rand;
$i++;
}
}
}
return $array;
}
function alert($header, $messenge) {
$alert = '<b>' . $header . '</b><br/>' . $messenge .'<br/>';
print("$alert");
}
function header_of_form($header, $messenge) {
$output = '' . $header . '<br/>' . $messenge . '<br/>';
return $output;
}
function month($m) {
switch ($m) {
case "1":
$month = "Январь";
break;
case "2":
$month = "Февраль";
break;
case "3":
$month = "Март";
break;
case "4":
$month = "Апрель";
break;
case "5":
$month = "Май";
break;
case "6":
$month = "Июнь";
break;
case "7":
$month = "Июль";
break;
case "8":
$month = "Август";
break;
case "9":
$month = "Сентябрь";
break;
case "10":
$month = "Октябрь";
break;
case "11":
$month = "Ноябрь";
break;
case "12":
$month = "Декабрь";
break;
}
return $month;
}
function statistic($id, $sizer, $show, $cliks) {
$set = select("SELECT COUNT(*) FROM `statistic` WHERE `id` = $id AND `sizer` = $sizer AND `date` = CURDATE()");
$count = mysql_result($set, 0, 0);
if ($count > 0) updata("UPDATE `statistic` SET `show` = `show` + $show, `cliks` = `cliks` + $cliks WHERE `id` = '$id' AND `sizer` = '$sizer' AND `date` = CURDATE()");
else insert("INSERT INTO `statistic` VALUES('$id', '$sizer', '$show', '$cliks', CURDATE())");
}
function filter($st)
{
$st=ereg_replace("[:;""'~#%&()><?]","",$st);
return $st;
}
function filter_url($st)
{
$st=ereg_replace("[;""'~#%()><!*]","",$st);
return $st;
}
function filter_text($st)
{
$st=ereg_replace("[:;""'~#%()><*]","",$st);
return $st;
}
function IPDetect() {
$serverVars = array(
"HTTP_X_FORWARDED_FOR",
"HTTP_X_FORWARDED",
"HTTP_FORWARDED_FOR",
"HTTP_FORWARDED",
"HTTP_VIA",
"HTTP_X_COMING_FROM",
"HTTP_COMING_FROM",
"HTTP_CLIENT_IP"
);
foreach ($serverVars as $serverVar)
if (!empty($_SERVER[$serverVar]))
$proxyIP = $_SERVER[$serverVar];
if (!empty($proxyIP)) {
$isIP = preg_match('|^([0-9]{1,3}.){3,3}[0-9]{1,3}|', $proxyIP, $regs);
if ($isIP && (sizeof($regs) > 0))
return $regs[0];
}
return $_SERVER['REMOTE_ADDR'];
}
?>