<?php
//=========================
include_once("sql.php");
//=========================
$sw = $_GET['s'];
if($sw == "") {
$query = "SELECT url,click FROM rcount WHERE id='1'";
$result = mysql_query($query, $db);
if(!$result) {die("Не могу выполнить запрос".mysql_error());}
$row = mysql_fetch_row($result);
$count = ++$row['1'];
$query_a = "UPDATE rcount SET click = {$count} WHERE id='1'";
if(!mysql_query($query_a, $db)) {die("Не могу обновить данные");}
header('Location: '.$row['0']);
} else {
$query = "SELECT url,click FROM rcount WHERE id={$sw}";
$result = mysql_query($query, $db);
if(!$result) {die("Не могу выполнить запрос".mysql_error());}
$row = mysql_fetch_row($result);
$count = ++$row['1'];
$query_a = "UPDATE rcount SET click = {$count} WHERE id={$sw}";
if(!mysql_query($query_a, $db)) {die("Не могу обновить данные");}
header('Location: '.$row['0']);
}
?>
sql.php:
<?
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_db = "rCount";
//=========================
$db = mysql_connect($db_host, $db_user, $db_pass);
if(!mysql_select_db($db_db, $db)) {die("Не могу выбрать базу данных");}
?>
adm.php:
<form method="post">
Адрес сайта :<input type="text"name="site" value="http://">
<input type="submit"name="add"value="Добавить">
</form>
<?echo "===================================================================<br />";
//=========================
include_once("sql.php");
//=========================
if (!empty($_POST['add'])) {
$site = $_POST['site'];
$sql = mysql_query("INSERT INTO rcount (url) VALUES ('$site')");
echo 'Ваш сайт <b>'.$_POST['site'].'</b> успешно добавлен!';
$id = mysql_insert_id($db);
echo "<br /><b>ID:</b> " . $id . "<br />";
}
echo "===================================================================<br />Посмотреть <a href=stat.php>статистику</a>";
mysql_close($db);
?>
stat.php:
<?php
/*
>=======================================<
–Файл: stat.php–
–Назначение: сбор статистики–
>=======================================<
*/
include_once("sql.php");
?>
<html>
<head>
<title>Статистика rCount</title>
</head>
<body>
<table border="1" cellspacing="1" width="300px" height="100%">
<tr>
<td width="30px" height="20px">
<b>ID</b>
</td>
<td width="200px" height="20px">
<b>URL</b>
</td>
<td width="40px" height="20px">
<b>CLICKS</b>
</td>
</tr>
<?php
$sql = "SELECT * FROM rcount";
$result = mysql_query($sql);
if(!$result){die("Не могу выполнить запрос" . mysql_error());}
while($row = mysql_fetch_array($result)) {
?>
<tr>
<td width="30px" height="20px">
<?php echo $row['id'];?>
</td>
<td width="200px" height="20px">
<a href="http://1.t/<?php echo $row['id']?>"><?php echo $row['url'];?></a>
</td>
<td width="40px" height="20px">
<?php echo $row['click'];?>
</td>
</tr>
</body>
</html>
<?php
}
mysql_close($db);
?>
Вот такое говнорешение ))))