CREATE TABLE supporters_ips( id VARCHAR( 15 ) NOT NULL, ip VARCHAR( 100 ) NOT NULL ); CREATE TABLE supporters( id INT( 11 ) NOT NULL AUTO_INCREMENT , PRIMARY KEY ( id ) , site_adress VARCHAR( 100 ) NOT NULL , site_title VARCHAR( 100 ) NOT NULL , hits VARCHAR( 100 ) NOT NULL DEFAULT '0' );
That creates the tables.
Now for supporters_config.php
<?php $db_user = "YOUR USERNAME"; $db_pass = "YOUR PASS"; $db_host = "localhost"; $db_name = "YOUR DATABASE"; $mysql_access = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name); ?>
That just connects to the database.
Now view_hits.php this is your admin panel to view the number of hits that the site sends to you, and to add new sites.
<body bgcolor="#000000">
<b>
<center><table width="500" border="1" bgcolor="#2A7FFF">
<tr>
<td width="66%"><center>
<b><u>Site Name:</u></b>
</center></td>
<td width="33%"><center>
<b><u>Number of sent hits</u></b>:
</center></td>
</tr>
<?php
include 'supporters_config.php';
//select the table
$result = mysql_query("select * from supporters");
//grab all the content
while($r=mysql_fetch_array($result))
{
$site_title=$r["site_title"];
$site_address=$r["site_adress"];
$number_of_hits=$r["hits"];
$id=$r["id"];
//display the row in a table
echo "<tr>
<td width=\"66%\"><center><b><a href='$site_address' target='_blank'>$site_title</a></b></center></td>
<td width=\"33%\"><center><b>$number_of_hits</b></center></td>
</tr> ";
}
?>
</table>
<p>
<a href="add_new.php">Add a new site</a>
</center>
</b>
</body>Now add_new.php, this adds a new site (what a suprise).
<body bgcolor="#030003">
<b>
<center>
<table border="0" bgcolor="#2A7FFF">
<tr>
<th scope="row"><b>
<?php
include 'supporters_config.php';
if($_POST['submit']){
$site_name = $_POST['site_name'];
$site_address = $_POST['site_address'];
if ($site_name == ""){
echo "One or more fields are left blank.";
}
elseif($site_address == ""){
echo "One or more fields are left blank.";
} else {
$sql=mysql_query("INSERT INTO `supporters` ( `site_title` , `site_adress` ) VALUES ('$site_name', '$site_address')");
$result = mysql_query("select * from supporters limit 1");
//grab all the content
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
//display the row
echo "Congratulations, you have successfully added a new site. That new site's id is $id.<p><a href=\"view_hits.php\">Go back?</a>";
}
}
} else {
?>
<form action="?submit=true" method="post" name="form1" id="form1">
<label>Site Name:
<input type="text" name="site_name" />
</label>
<p>
<label>Site Address:
<input type="text" name="site_address" />
</label>
</p>
<p>
<label>
<input type="submit" name="submit" value="Submit" />
</label>
</p>
</form>
<?php
}
?>
</b></th>
</tr>
</table>
</center>
</b>
</body>Now in.php, this page is what counts the incoming hits.
<?php
ob_start();
include('supporters_config.php');
$id=$_GET['id'];
if (is_numeric($id)) {
$ip = $_SERVER['REMOTE_ADDR'];
$sql22 = @mysql_query("SELECT * FROM supporters_ips where id = '$id' and ip = '$ip'");
$unique_visitors = @mysql_num_rows($sql22);
if ($unique_visitors == 0){
$sql2=mysql_query("INSERT INTO `supporters_ips` ( `id` , `ip` ) VALUES ('$id', '$ip')");
$sql=@mysql_query("SELECT * FROM supporters WHERE id = $id LIMIT 1");
$r=@mysql_fetch_array($sql);
$hits=$r['hits'];
$hits++;
mysql_query("UPDATE supporters SET hits = '$hits' WHERE id = '$id'");
//Everything is successfull!
header("Location: index.html");
} else {
header("Location: index.html");
}
} else {
header("Location: index.html");
}
ob_end_flush();
?>Remember to change the header("Location: index.html") to header("Location: YOUR_SITE'S_HOMEPAGE").
Well that is about the whole tutorial. Please try to leave credit, as this took time to write.













Sign In
Register
Help



MultiQuote