Lost Password?


  #1 (permalink)  
Old 10-28-2007, 08:25 PM
Jaan's Avatar   
Jaan Jaan is offline
Mod
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 930
Last Blog:
AdStar Ad Control Pa...
Rep Power: 16
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Links redirection page with stats

Okay now i'm going to teach y'all how to keep records about your links.. see how many times they have been clicked, when and what addresses..

First we must create one table:

MySQL Code:
  1. CREATE TABLE `test`.`links` (
  2. `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ;
  3. `url` VARCHAR( 100 ) NOT NULL ,
  4. `clicks` INT( 10 ) NOT NULL ,
  5. `TIME` VARCHAR( 10 ) NOT NULL ,
  6. `DATE` VARCHAR( 30 ) NOT NULL
  7. ) ENGINE = INNODB

Now let's create the main script: links.php

PHP Code:
<?php

// Define URL and some other stuff
$url $_GET['url'];
$date date("l, jS F, Y");
$time date("H:i");

if(!isset(
$url) || empty($url) || $url == ""){
die(
"<h1>You don't have permissions to view this file!</h1>");


// Connect to database
$con mysql_connect("localhost""username""password");
if(!
$con){
die(
mysql_error());
}

// Select your database
$selDB mysql_select_db("database"$con);
if(!
$selDB){
die(
mysql_error());
}

// Now let's find do we have any records about the url you entered
$findURL mysql_query("SELECT * FROM links WHERE url='$url'");
$findURLnum mysql_num_rows($findURL);

// If we don't have any, let's create it's first record
if($findURLnum == "0"){
$insert mysql_query("INSERT INTO links (url, clicks, time, date) VALUES ('$url', '1', '$time', '$date')");
if(!
$insert){
die(
mysql_error());
// If we have records about that url, let's update it
}
}elseif(
$findURLnum != "0"){

$findClicks mysql_query("SELECT * FROM links WHERE url='$url'");
$query mysql_fetch_array($findClicks);
$findClicksOld $query['clicks'];
$oldnum $findClicksOld;
$newnum =1;
$clicksNew $oldnum+$newnum;

// Update clicks
$updateClicks mysql_query("UPDATE links SET clicks='$clicksNew' WHERE url='$url'");
if(!
$updateClicks){
die(
mysql_error());
}

// Update time
$updateTime mysql_query("UPDATE links SET time='$time' WHERE url='$url'");
if(!
$updateTime){
die(
mysql_error());
}

// Update date
$updateDate mysql_query("UPDATE links SET date='$date' WHERE url='$url'");
if(!
$updateDate){
die(
mysql_error());
}

}

?>
Now let's create that HTML part:

HTML Code:
<html>
<head>
<?php
echo "<META http-equiv='refresh' content='3;URL=$url'>";
?>
</head>
<body>
<center><font color="#FF0000">You will be redirected to <?php echo $url; ?>!</font></center>
</body>
</html>

Here's full script:

Code:
<?php

// Define URL and some other stuff
$url = $_GET['url'];
$date = date("l, jS F, Y");
$time = date("H:i");

if(!isset($url) || empty($url) || $url == ""){
die("<h1>You don't have permissions to view this file!</h1>");
} 

// Connect to database
$con = mysql_connect("localhost", "username", "password");
if(!$con){
die(mysql_error());
}

// Select your database
$selDB = mysql_select_db("database", $con);
if(!$selDB){
die(mysql_error());
}

// Now let's find do we have any records about the url you entered
$findURL = mysql_query("SELECT * FROM links WHERE url='$url'");
$findURLnum = mysql_num_rows($findURL);

// If we don't have any, let's create it's first record
if($findURLnum == "0"){
$insert = mysql_query("INSERT INTO links (url, clicks, time, date) VALUES ('$url', '1', '$time', '$date')");
if(!$insert){
die(mysql_error());
// If we have records about that url, let's update it
}
}elseif($findURLnum != "0"){

$findClicks = mysql_query("SELECT * FROM links WHERE url='$url'");
$query = mysql_fetch_array($findClicks);
$findClicksOld = $query['clicks'];
$oldnum = $findClicksOld;
$newnum =1;
$clicksNew = $oldnum+$newnum;

// Update clicks
$updateClicks = mysql_query("UPDATE links SET clicks='$clicksNew' WHERE url='$url'");
if(!$updateClicks){
die(mysql_error());
}

// Update time
$updateTime = mysql_query("UPDATE links SET time='$time' WHERE url='$url'");
if(!$updateTime){
die(mysql_error());
}

// Update date
$updateDate = mysql_query("UPDATE links SET date='$date' WHERE url='$url'");
if(!$updateDate){
die(mysql_error());
}

}

?>
<html>
<head>
<?php
echo "<META http-equiv='refresh' content='3;URL=$url'>";
?>
</head>
<body>
<center><font color="#FF0000">You will be redirected to <?php echo $url; ?>!</font></center>
</body>
</html>
I will create stats page part later
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
vB Weekly Stats Version 1.7 Jordan Community Projects 51 02-11-2008 12:25 PM
How to add links to your site? c0de Tutorials 2 09-16-2007 02:42 PM
how to refresh a page? :-[yc]-: Java Help 2 05-30-2007 08:47 AM
Does Google Penalize for too many inbound links Cleo8 Search Engine Optimization 6 04-23-2007 05:56 PM
The ultimate xHTML / DHTML / HTML 301 redirection thread! Dan HTML Programming 5 07-04-2006 06:57 PM


All times are GMT -5. The time now is 12:42 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads