Jump to content
xisto Community
Sign in to follow this  
aka-2

How To Avoid The Bandwidth Robbery How to avoid the bandwidth robbery

Recommended Posts

Sometimes, some people link directly to images in your host. This people is robbering you bandwidth. To avoid this only have to write some code lines in your .htaccess file in your host root:

 

RewriteEngine On

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^https://sedo.com/us/services/broker-service/?language=us?tracked=&partnerid=&language=us [NC]

RewriteCond %{HTTP_REFERER} !^https://sedo.com/us/services/broker-service/?language=us?tracked=&partnerid=&language=us [NC]

RewriteRule .*\.(gif|jpg|swf|png)$ - [NC,F]


There is another thing you can do. You can also show an image you want instead linked images. So the people that has been robbering you bandwidth will take a surprise. Just ad this to code:

 

RewriteRule .*\.(gif|jpg)$ http://forums.xisto.com/no_longer_exists/ [R,NC]

I hope you enjoy this.

Share this post


Link to post
Share on other sites

Here at the Xisto, once you are Hosted, you can also use the Hotlink Protection in the Cpanel to do this same thing. Similar to the Tutorial, you specify the domain names which you allow to link to your Images. Nice Tutorial, though. Short and sweet.

Share this post


Link to post
Share on other sites

Ya that is always a good idea to keep people from robbing you of your bandwidth. I think if people want to view things they should go to your site to view them so you can maybe get a few more customers out of it or visitors atleast. I don't really have a reason to do this though at the moment but I like the idea.

Share this post


Link to post
Share on other sites

I don't like to restrict images to certain referals, since some people block referals or change the referal fields to "google.com" or something... which means pictures on your site will appear as whatever you don't want...

Share this post


Link to post
Share on other sites

I don't like to restrict images to certain referals, since some people block referals or change the referal fields to "google.com" or something... which means pictures on your site will appear as whatever you don't want...

If you have a good knowledge of .htaccess files and PHP, then you could probably make a message appear asking them to use their normal referer.

Share this post


Link to post
Share on other sites

Thank you jlhaslip, i didn't know that feature. Really, I have never had to use these tricks, but it's a good idea to keep people from robbing you of your bandwidth.

 

Usually, people who do this are people who begin blogging and who don't know that they are making something bad.

 

Ok, the code would have to be:

 

RewriteRule .*\.(gif|jpg)$ http://your-domain/name-of-substitute-image.gif [R,NC]

or maybe just:

 

RewriteRule .*\.(gif|jpg)$ http://your-domain/image.gif [R,NC]
:)

Share this post


Link to post
Share on other sites

A great tutorial. It's always nice to have the ability to be able to keep control of the bandwidth without using the cpanel hotlink protection, whether it be because the server doesn't support it (this certainly isn't the case with Xisto) or because for whatever reason the user doesn't want to bother with hotlink protection (I don't really know why this would be the case though).If I ever end up without a hotlink protection in a cpanel, I will almost certainly use this code for the htaccess, as it will ensure that no-one else can consume all of my bandwidth. Thanks for sharing.

Share this post


Link to post
Share on other sites

JpOlDeRmAn, surely you don't understand this tutorial bacause you don't have this problem, but maybe this long explanation can help you to undesrtand:Bandwidth robbery, bandwidth theft or "hotlinking" is direct linking to a web site's files (images, video, etc.). An example would be using an <img> tag to display a JPEG image you found on someone else's web page so it will appear on your own site, weblog, etc.Bandwidth refers to the amount of data transferred from a web site to a user's computer. When you view a web page, you are using that site's bandwidth to display the files. Since web hosts charge based on the amount of data transferred, bandwidth is an issue. If a site is over its monthly bandwidth, it's billed for the extra data or taken offline.A simple analogy for bandwidth theft: Imagine a random stranger plugging into your electrical outlets, using your electricity without your consent, and you paying for it.

Share this post


Link to post
Share on other sites

Other way to take advantage of this theft is to make publicity of your site. Whem someone links directly to one of the photos of your site, the script create a box around the photo with the name of your site, or with anything you want.

 

This script use GD Library, so it's very usefull:

 

<?php

 

// *** Configuration start

 

// Web server root path

$web_root = "/Users/daniel/Sites/";

 

// Cache directory. Need write permissions

$path_cache = "/Users/daniel/Sites/cache/";

 

// Default photo.

$default_photo = "/default.jpeg";

 

// Tag

$tag = "http://forums.xisto.com/no_longer_exists/;;

 

// *** Configuration end

 

/*

* Transforms a palette image into a truecolor image. Leaves truecolor images

* untouched.

*/

function imagepalettetotruecolor(&$img)

{

if (!imageistruecolor($img)) { // GIF format is not truecolor

$w = imagesx($img);

$h = imagesy($img);

$img1 = imagecreatetruecolor($w, $h); // Create a new truecolor image

imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); // Copy old image over

$img = $img1; // Change the image handler

}

}

 

/*

* Process an image. The parameter is the path to the image. The result image is

* saved over the old image.

*/

function process_image($photo)

{

global $tag;

 

// Create an iamge handler from any known format

$im = imagecreatefromstring(file_get_contents($photo));

imagepalettetotruecolor($im);

$white = imagecolorallocate($im, 255, 255, 255);

$black = imagecolorallocate($im, 0, 0, 0);

 

// Add the tag using font #2

// Add a background rectangle.

$tag_width = imagefontwidth(2) * strlen($tag) + 1;

$tag_height = imagefontheight(2) + 2;

imagefilledrectangle($im, 0, 0, $tag_width, , $black);

imagestring($im, 2, 1, 1, $tag, $white);

 

// Save the image in jpeg.

imagejpeg($im, $photo);

imagedestroy($im);

}

 

// Get the image to "tag"

if ($_GET['photo'] != "") { // URL parameter for testing

$photo_url = $_GET['photo'];

} else if ($_SERVER['REQUEST_URI'] != "") { // Request URL for production

$photo_url = $_SERVER['REQUEST_URI'];

} else { // or a default image

$photo_url = $default_photo;

}

 

// The path to the real image

$photo_path = $web_root . $photo_url;

 

// The path to the cached image. The md5 avoids name clashes.

$photo_cache = $path_cache . md5($photo_url);

 

if (is_file($photo_path)) { // We test if there is really an image

if (!is_file($photo_cache)) { // If the image is not yet cached

// Copy over the cache

copy($photo_path, $photo_cache) or die('Error copying the image');

 

// Process the cached image

process_image($photo_cache);

}

 

if (is_file($photo_cache)) { // If we have the image in the cache

// Send the image mime type and length

header("Content-Type: image/jpeg");

header("Content-Length: " . filesize($photo_cache));

readfile($photo_cache);

} else {

die('Image not in the cache');

}

} else {

die('Image not found ' . $photo_url);

}

?>


To finish the work and complete the code you have to write in your .htaccess in the hosting root the next lines:

 

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http://dp.g.doubleclick.net/apps/domainpark/domainpark.cgi?client=&domain_name=eldominio.com&channel=&drid=&output=html(/)?.*$ [NC]

RewriteRule .*.(gif|jpg|jpeg|bmp|png)$ /image.php [NC]


You can download this file directly from here.

 

Here you can see an example of the script running.

 

The original work of this script is here, in spanish.

Share this post


Link to post
Share on other sites

It?s not just a nice tutorial, it?s vital. I find hotlinking completely necessary. I am a truly believer of freedom of information in internet and I don?t mind people pick my images (or texts) and publish them everywhere, but at least take some time to save it and set it up in your own server... it?s such bad education, to steal contents and also bandwidth, having something completely for free just by stealing it.I have the hotlink protection activated in Cpanel... a really helpful feature.

Share this post


Link to post
Share on other sites

Thanks that is a nice tutorial. I'm just starting to learn aobut .htaccess and it is quite interested. This looks like it use mod_rewrite which is very cool. Ive used this in my upcoming forum which uses a modification to rewrite the urls to search engine optimize them. Ive also seen that .htaccess is very powerful because you can change a whole lot of file types to another by entering one line of code in your .htaccess file which can be very useful across some large sites. Anyway this was a great tutorial and i might use it on a imgehost if i get round to doing one :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.