[Tutorial] Leech control

Example of PHP code.

Moderator: Moderators

[Tutorial] Leech control

Postby Phantom on Sat Jul 09, 2005 3:59 pm

Some people, including myself, are webmasters to a site that hosts many videos and other forms of media. Most of the time, when the word is spread, direct links are posted rather than a link to the page on the host's site. So thus, as a solution, I have conjured a small counter to that problem. This leech control does not require long lines of coding. Rather, it is quite a small code. Let's begin, shall we?

First we'll start of by adding the ob_start() function. This allows us to continually send headers in your page.

Code: Select all
<?PHP

ob_start();

Next, let's define a few variables. We'll start with the page itself.

Code: Select all
$page = $_SERVER['PHP_SELF'];

Pretty self explanitory. Now let's continue to defining the IP. This is the key to this leech control, as you will see in a few moments.

Code: Select all
$ip = $_SERVER["REMOTE_ADDR"]; // This defines the actual IP address of the user
$dotip = str_replace (".", "", $ip); // This removes the dots in the IP (ex: 12.34.56 -> 123456)

Using the str_replace() function, we remove the dots to have a solid number. With me so far? Let's continue. With the following line of code, we generate our leech control. In this case, we will md5() the dotless IP to create a unique ID per computer.

Code: Select all
$leech = md5 ($dotip);

I told you it was simple. Now let's make a sample code of how to use this:

[code highlight="12-19"]if ($id == '2')
{
if ($_GET['dl'] !== 'yes')
{
echo <<<HTML
<b>Download Item #2</b><br /><br />
<a href="$page?id=2&dl=yes&auth=$leech">Click here to download</a>!
HTML;
}
else
{
if ($_GET['auth'] === $leech)
{
print "This is the page where your download will begin.";
}
else
{
header ("Location: " . $page . "?id=2");
}
}
}
else
{
print "<b>Download Items</b><br /><br />Download Item #1<br /><a href='" . $page . "?id=2'>Download Item #2</a>";
}[/code]
Most of the above coding is simply ifs and elses, but the line I want you to pay close attention to is lines 12-19. It makes sure if the $_GET['auth'] that was generated in line 7 is equal to the person's dotless IP md5ed, it will allow that person to go to the next step. But if it is not equal, they are automatically sent to the download page where they must click their own unique link using the header() function.

And finally, we will end the page off with the ob_end_flush() function to output the headers.

Code: Select all
ob_end_flush();

?>


There it is, plain and simple. If you don't believe me, try clicking this link:

http://trickingit.com/phantom/authleech ... e3889541e5

That's a demo page for this small leech control code. The auth variable is my IP dotless in md5 form. When you go to that link, look at your address bar. You should be automatically redirected to http://trickingit.com/phantom/authleech.php?id=2. This is because your dotless IP md5 is not the same as mine. Now try clicking the link provided. Voila! You have your own little leech control.

Hope this helps in one form or another.

// Phantom
"Best of the best of the best, sir! With honors!" -- MIB
[ jphantom.com ]
Phantom
Registered User
Registered User
 
Posts: 245
Joined: Mon Apr 18, 2005 3:24 am

Return to PHP Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest