Link Cloaking Code

Status
Not open for further replies.
yes, but this would be better
Code:
CREATE TABLE `links` (
  `id` int(4) NOT NULL auto_increment,
  `code` varchar(20) NOT NULL default '',
  `url` varchar(200) NOT NULL default '',
[B]  `comments` TEXT,[/B]
  `visits` int(11) NOT NULL default '0',
  PRIMARY KEY  (`code`),
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM
TEXT allows you to use longer comments in natural language...varchar is limited to 255 chars and they are not enough when you want to make clear the difference from other similar links, I removed NOT NULL default ' ' so you can leave it blank but I'm not sure it's necessary, the white space might do the same
 


this code is experimental - just quick & dirty.
try it and make it better, because its a good base to start from.

a few features, like the swf redirect are not implemented.
but its easy to do it. have fun ;)

-------------------------------------------------------------

sql

Code:
CREATE TABLE `clicks` (
  `lid` int(10) unsigned NOT NULL default '0',
  `gid` int(10) unsigned NOT NULL default '0',
  `ref` text NOT NULL,
  `oref` text NOT NULL,
  `ip` varchar(15) NOT NULL default '',
  `ua` varchar(255) NOT NULL default '',
  `target` varchar(255) NOT NULL default '',
  `ts` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`lid`,`ip`,`ts`)
):
CREATE TABLE `groups` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  UNIQUE KEY `id` (`id`)
);
CREATE TABLE `links` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `gid` int(10) unsigned NOT NULL default '0',
  `url` varchar(255) NOT NULL default '',
  `type` set('meta','js','replace','head') NOT NULL default 'head',
  `cookie` varchar(255) NOT NULL default '',
  UNIQUE KEY `id` (`id`)
);
.htaccess
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(group)?([0-9]+)/?(.*?)/?$ index.php?link=$2&ref=$3&group=$1 [L,QSA]
index.php
Code:
<?php

if( !$_GET['link'] ) exit;
if( strpos( $_SERVER['HTTP_REFERER'], 'administration' ) !== false ) exit;

if( is_numeric( $_GET['link'] ) ) {
        mysql_connect( 'localhost', 'root', 'xxxxxx' );
        mysql_select_db( 'linktrack' );

        if( $_GET['group'] == 'group' ) {
                $q = 'SELECT * FROM links WHERE gid = '.$_GET['link'].' ORDER BY RAND() LIMIT 1';
                $r = mysql_query( $q );
                if( mysql_num_rows( $r ) == 1 ) {
                        $link = mysql_fetch_assoc( $r );
                        $_GET['link'] = $link['id'];
                }
        }

        $q = 'SELECT * FROM links WHERE id = '.$_GET['link'];
        $r = mysql_query( $q );
        if( mysql_num_rows( $r ) == 1 ) {
                $link = mysql_fetch_assoc( $r );
                $q = 'INSERT INTO clicks SET
                        lid     = '.$link['id'].',
                        gid     = '.$link['gid'].',
                        oref    = "'.mysql_escape_string( $_GET['ref']                  ).'",
                        ref     = "'.mysql_escape_string( $_SERVER['HTTP_REFERER']      ).'",
                        ip      = "'.mysql_escape_string( $_SERVER['REMOTE_ADDR']       ).'",
                        ua      = "'.mysql_escape_string( $_SERVER['HTTP_USER_AGENT']   ).'",
                        target  = "'.mysql_escape_string( $link['url']                  ).'",
                        ts      = NOW()';
                mysql_unbuffered_query( $q );
                if( $link['type'] == 'meta' ) {
                        echo '<html><head><title>.</title>';
                        echo '<meta http-equiv="refresh" content="0; url='.$link['url'].'">';
                        echo '</head><body></body></html>';
                }
                elseif( $link['type'] == 'js' ) {
                        echo '<html><head><title>.</title>';
                        echo '<script type="text/javascript">location.href="'.$link['url'].'";</script>';
                        echo '</head><body></body></html>';
                }
                elseif( $link['type'] == 'replace' ) {
                        echo '<html><head><title>.</title>';
                        echo '<script type="text/javascript">location.replace("'.$link['url'].'");</script>';
                        echo '</head><body></body></html>';
                }
                else {
                        header( 'Location: '.$link['url'] );
                }
                exit;
        }
}



?>
/administration/index.php
Code:
<?php

session_start();

if( $_POST['auth'] == 'stupidpassprotection' ) {
        $_SESSION['ok'] = 1;
        header( 'Location: '.$_SERVER['HTTP_HOST'].'/administration/' );
        exit;
}

if( !$_SESSION['ok'] ) {
        include( 'auth.php' );
        exit;
}

include( 'functions.php' );
?>
<html>
<head>
<title>redirect0r</title>
<script type="text/javascript">
function showhide( i ) {
        if( document.getElementById( 'hidden-' + i ).className == 'script' ) {
                document.getElementById( 'hidden-' + i ).className = 'scriptshow';
        }
        else {
                document.getElementById( 'hidden-' + i ).className = 'script';
        }
}
</script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
if( is_numeric( $_GET['stats'] ) ) {
        include( 'page_stats.php' );
}
else {
        include( 'page_start.php' );
}
?>
</body>
</html>



...the rest is on nopaste - powered by ghcif.de
 
Status
Not open for further replies.