Xpazeman.com  
|   | ESTILO: red orange green blue pink |
ATOM
 
30-08-2006 15:11
Hotlink protect

Keywords:hotlink protect proteccion script web tutorial

 Enviar a un amigo   Versión para imprimir
 Snow Patrol - Wow

El hotlink es, a dia de hoy, un problema para los creadores de contenido. A mi no me importa que me cojan una imagen para colgarla en una página, es más, creo que en cierto modo ayuda a que se extienda por ahí mis obras. Pero el problema del hotlinking es más grave, porque entran en juego otros factores como el ancho de banda disponible para una página. Para los que no teneis muy claro qué es el hotlinking, os pongo un ejemplo:

Imagina que tienes una pagina: "Mipaginadelahostia.com". Ok,ahora, tu navegas por mi página y ves una imagen que te encanta, y quieres ponerla en la tuya. Puedes hacer dos cosas:
1. Te bajas la imagen, la subes a tu server y pones el tag como siempre para mostrar la imagen.
2. No tienes server propio, no tienes ni idea o lo que sea, así que coges y pones el tag así: img xsrc="imagen.jpg"

Pues la segunda manera es lo que se llama hotlinking, un problema, porque cada vez que alguien entra en tu página, la imagen se pide a mi servidor, por lo que se gasta ancho de banda, pero yo no he conseguido ninguna visita. El problema principal reside en que en estas páginas no se suele dar ningún tipo de crédito a las páginas de las que cogen las imágenes, ni un mísero link.

Así que ayer, tras ver que a mi me hacían algo parecido, decidí crearme un script para al menos conseguir algo de crédito. Se trata de una combinación entre el uso del .htaccess, PHP y la librería GD, una de las combinaciones más potentes para web de hoy en día.

El sistema a utilizar es sencillo, cuando el server reciba una petición de un jpg desde fuera de nuestro propio dominio, debe redireccionarla a un fichero PHP, que colocará una marca de agua o watermark sobre la imagen solicitada y luego la mostrará.

Si pulsais sobre leer más, teneis un tutorial sobre como configurar todo esto.

Configurar el servidor
El primer paso es configurar el servidor para que redireccione las peticiones, para ello, debes crear o editar el fichero .htaccess en el directorio principal de tu servidor (donde debe estar el index de tu página). Si hay algo escrito ¡no lo borres! simplemente añade el siguiente código al final:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} .*jpg$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !tuweb.com [NC]
RewriteCond %{HTTP_REFERER} !webamigo.com [NC]
RewriteCond %{HTTP_REFERER} !google. [NC]
RewriteCond %{HTTP_REFERER} !search?q=cache [NC]
RewriteRule (.*) /hotlinks.php?src=$1

El código puede llegar a ser un poco complicado, si quereis profundizar más en el mod_rewrite (que he de deciros que es muy MUY potente, podeis encontrar un tutorial sobre lo básico aqui.

RewriteEngine On
Esta línea activa el motor para realizar las conversiones del mod_rewrite.

RewriteCond %{REQUEST_FILENAME} .*jpg$ [NC]
Con esta línea hacemos que sólo se procesen las peticiones de ficheros jpg.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !tuweb.com [NC]
RewriteCond %{HTTP_REFERER} !webamigo.com [NC]
RewriteCond %{HTTP_REFERER} !google. [NC]
RewriteCond %{HTTP_REFERER} !search?q=cache [NC]

Con estas líneas lo que hacemos es que sólo se procesen las peticiones que vienen de algún dominio, que no sea el tuyo, ni el de tu amigo, ni de google. Recordemos que sólo deben pasar las peticiones que queremos marcar con marca de agua.

RewriteRule (.*) /hotlinks.php?src=$
Si el proceso ha llegado hasta aquí es porque se trata de una petición de un jpg realizada desde una web que no queremos que lo haga impunemente. Por lo que llamamos al fichero que procesará la imagen, pasando como parámetro la ruta completa de la imagen.

Preparar el Script
El siguiente paso es preparar el script. Para ello, debemos primero crear con Photoshop una imagen que queramos usar como watermark (marca de agua). Recomiendo que sea una imagen pequeña, de unos 80-100 píxeles de ancho y unos 15-30 de alto. Debemos guardarla como PNG-8 (PNG-24 produce errores con algunas versiones de la librería GD) y con el nombre "watermark.png".

Una vez tengamos la imagen, pasemos de lleno al script:

1. Dado que lo que se está pidiendo es una imagen, debemos cambiar la cabecera para que se muestre la imagen correctamente, ya que por defecto es de tipo texto (daría un error mostrando la imagen de dejarlo así)

header('content-type: image/jpeg');

2. Tras esto, debemos cargar en memoria la imagen que vamos a usar como marca de agua, y además tomarle las medidas.

$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);

3. Ahora creamos una imagen nueva a partir de la imágen que se ha solicitado. Recordemos que la ruta se pasaba como parámetro (src).

$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($_GET['src']);
$size = getimagesize($_GET['src']);

4. Con las dos siguientes líneas, establecemos la x e y para la posición donde colocaremos la marca de agua (abajo a la derecha y con cinco píxeles de margen).

$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;

5. Por último, colocamos la imagen watermark sobre la imagn solicitada, y mediante la función imagejpeg() la mostramos. Después destruimos de memoria las imágenes utilizadas (para no ocupar recursos, lo que se borra está en memoria, no se borra la imagen real)

imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);

Y con esto ya estaría listo. El código completo es el sigiente:

hotlinks.php:

header('content-type: image/jpeg');
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($_GET['src']);
$size = getimagesize($_GET['src']);
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);

?>

Sólo nos quedaría ahora subir tanto las modificaciones del .htaccess como el fichero hotlinks.php. Acordaos de poner vuestro sitio en el .htaccess!

Espero que os sea útil, podeis contactar conmigo a través de los comentarios, o mandando un mensaje desde el área de contacto

TAGS: tutorial web 
 
Rating: 34 (+ / -)
 
Autor: Xpazeman
 
Categoria: Tutoriales

58 comentarios
Re:HOTLINK PROTECT
30-08-2006 15:39

clap clap clap clap


brutal !!!!!! :D

Por: te

Re:HOTLINK PROTECT
30-08-2006 16:20

Grazze grazze, se hace lo que se puede.

:)

Por: Xpz

Re: Hotlink protect
07-01-2008 20:29

Lo hice y no dio resultados segun yo hice todo tal y como se indica, no se lo que haya pasado

Por: perisl

Re: Hotlink protect
14-01-2008 06:12

Ya lo tengo en funcionamiento en mi pagina web, es excelente!!

Web  
Por: dj_truco

Re: Hotlink protect
20-05-2008 20:00

Muchisimas gracias, me ha sido de mucha ayuda, en mi web no paran de robarme ancho de banda y con esto he podido ponerles marca a las fotos y que asi al menos se conozca un poco más mi web.

Gracias de nuevo ;)

Web  
Por: Ruth

Re: Hotlink protect
21-05-2008 10:37

Me alegro mucho de que te haya servido. ¡Gracias por el comentario!

Por: Xpazeman

Re: Hotlink protect
14-05-2011 19:16

If you want to buy a house, you would have to receive the credit loans. Furthermore, my sister always uses a sba loan, which seems to be really rapid.

Web  
Por: Mallory

Re: Hotlink protect
19-05-2011 09:56

Do you recognize the particular within education and experience? Education is when you read the attractive issue; experience is what you get when you don't. online papers, get superb experience with us!

Web  
Por: Elnora

Re: Hotlink protect
21-05-2011 04:23

From time to time different people do not recognize, what does directories submission stand for. Thus, they begin to do it themselves, which is not very wise, just because they can get a ban. I advice to utilize the experienced manual directory submission service to foreclose that.

Web  
Por: Priscilla

Re: Hotlink protect
22-05-2011 09:56

The correct way to check the professionalism of the custom thesis writing services was to purchase some supreme legal dissertation relating with this good post in dissertations writing services.

Web  
Por: Tamra

Re: Hotlink protect
23-05-2011 22:05

Different students do not know exactly the correct way to finish their biographies essays paper. Thence, at present time they can follow your good enough outcome & create the highest quality book reports e'er.

Web  
Por: Kristina

Re: Hotlink protect
17-06-2011 18:41

Performing my website I met a problem of stolen content. It has got big harm to me! Luckily, my brother suggested me to try the plagiarism detection. In fact, my site is getting well at this moment.

Web  
Por: Gwen

Re: Hotlink protect
20-06-2011 18:03

Your blog is absolutely fantastic! Lots of great information and inspiration, both of which we all need!

Web  
Por: Self assessment tax returns

Re: Hotlink protect
26-06-2011 14:49

Everybody loves bon bons! Cheers from France

Web  
Por: Bonbons

Current Mortgage Rates
27-06-2011 14:01

Your post is very good and design are very awesome i really like it. Thanks a lot!!!

Web  
Por: Anónimo

Re: Hotlink protect
18-07-2011 23:58

Some times happens that we need to get know referring to this topic and in that case that is good to use a support of the reliable custom writing service and buy an essay only there.

Web  
Por: Cathleen

Re: Hotlink protect
19-07-2011 21:27

I will probably buy essays or the custom written essay about this good post. A kind of great article! Thanks for that!

Web  
Por: Mollie

Re: Hotlink protect
08-08-2011 01:06

HI folks! You are welcome to our directories submission service with the knowledge, skills and the newest methods of submit that consistently deliver the best results!

Web  
Por: Ernestine

Re: Hotlink protect
11-08-2011 22:00

A PhD degree is really important issue for anybody. What companies should assist scholars in writing thesis about this good topic completing? We have to suggest to buy the dissertation in the thesis writing services. Hope that this advice can help you!

Web  
Por: Margarita

Re: Hotlink protect
11-08-2011 22:18

Your supreme stuff referring to this topic could be a base for thesis service or custom dissertation and be taken in format thesis.

Web  
Por: Katelyn

Re: Hotlink protect
13-08-2011 10:18

It's such a terrific post, that I've forwarded it to my friends!
Tax Return

Web  
Por: Tax Return

Mulberry for Target
20-08-2011 05:56

Your Daria Lengthy mulberry bayswater bags are usually yet another distinctive fashion perhaps your Cheap Mulberry Alexa Bag. The following wallet design and style can be purchased in tender leather-based that has a spongy conclude.

Web  
Por: Mulberry for Target

Re: Hotlink protect
21-08-2011 15:33

My wife told me to read your blog as it is really interesting, and I must admit she was not wrong at all.

Web  
Por: Play Sand

Re: Hotlink protect
25-08-2011 16:31

opbmvyqb{fnbo, ptfxuqptts

Web  
Por: vvmwataoss

Re: Hotlink protect
30-08-2011 08:38

Very interesting and informative article indeed. I have to admit that I always follow all news about this.

Web  
Por: School Papers

Re: Hotlink protect
05-09-2011 15:17

way to check the professionalism of the custom thesis writing services was to purchase some supreme legal dissertation relating with this good post in dissertations writing services.

Web  
Por: Cheap Web Designers

Re: Hotlink protect
05-09-2011 15:32

Your post is very good and design are very awesome i really like it. Thanks a lot!!!

Web  
Por: nero interesting facts

Re: Hotlink protect
07-09-2011 19:11

Your blog is absolutely fantastic! Lots of great information and inspiration, both of which we all need!

Web  
Por: fotocamere

Re: Hotlink protect
13-09-2011 17:23

Thanks a lot for a bunch of good tips. I look forward to rea
ding more on the topic in the future. Keep up the good work!
This blog is going to be great resource. Love reading it.

Web  
Por: traumdeutung

Re: Hotlink protect
21-09-2011 15:07

pspxyyqb{fnbo, ioygwkpuqx

Web  
Por: fdewchsczg

Re: Hotlink protect
06-10-2011 15:35

yholeyqb{fnbo, vyjvozqtqy

Web  
Por: aeueynwggp

Re: Hotlink protect
13-10-2011 12:25

Took a lot of time to read but I really found this very interesting and informative, thank you buddy for sharing.

SEO Company
SEO Services
SEM Services

Por: Alvina Charlotte

Re: Hotlink protect
13-10-2011 12:27

Very nice post even i would say that whole blog is awesome. I keep learning new things every day from post like these. Good stuff!

Web  
Por: SEO Company

Re: Hotlink protect
18-10-2011 21:58

lyqxiyqb{fnbo, kfuxedatff

Web  
Por: hdctrhbblk

Re: Hotlink protect
19-10-2011 14:32

Great post.Can i Share it with my friends?

Web  
Por: Plumber Milton Keynes

Re: Hotlink protect
20-10-2011 15:12

woxjfyqb{fnbo, fldjryajnc

Web  
Por: zuqqizomde

Re: Hotlink protect
21-10-2011 02:56

So the next time you feel like affairs yourself a Classic Chanel handbag, you will not accept to anguish about traveling all the way to a store. You can artlessly buy it in cheap handbags! chanel handbags,chanel wallets
cheap air jordan
women jordan 18 max
women nike dunk shoes
air jordan kid shoes
2011 adidas clima cool
free shipping for ugg boots
free shipping for women ugg boots

Web  
Por: cheap air jordan

Re: Hotlink protect
21-10-2011 04:20

ddbgkyqb{fnbo, obesosfjjp

Web  
Por: gzkiwhgstc

Re: Hotlink protect
21-10-2011 08:24

hhrmpyqb{fnbo, eeuxhvxvxx

Web  
Por: gjzjfacila

Re: Hotlink protect
21-10-2011 12:22

ptkhryqb{fnbo, thgzcetlzy

Web  
Por: utwrobxejn

Re: Hotlink protect
22-10-2011 11:22

So the next time you feel like affairs yourself a Classic Chanel handbag, you will not accept to anguish about traveling all the way to a store. You can artlessly buy it in cheap wallets! chanel handbags,
cheap air jordan
women jordan 18 max
women nike dunk shoes
men shoes
nike air max shoes

Web  
Por: cheap air jordan

News Bollywood
23-10-2011 07:54

nice information provided, news and entertaiment

Web  
Por: Latest Bollywood News

Re: Hotlink protect
23-10-2011 21:18

tvepbyqb{fnbo, ysvrxnikpx

Web  
Por: gysobdevxx

Re: Hotlink protect
24-10-2011 01:07

xutcdyqb{fnbo, kwmzysmlpl

Web  
Por: kwaaokvodl

Re: Hotlink protect
24-10-2011 04:57

tgbjlyqb{fnbo, mlotyptbmf

Web  
Por: rdegffzdnb

Re: Hotlink protect
24-10-2011 08:44

qhpnlyqb{fnbo, xoauwwjbpq

Web  
Por: ebuzvpcpji

Re: Hotlink protect
24-10-2011 12:36

jveonyqb{fnbo, ablexdvvpx

Web  
Por: qzfclkpgpr

answer this post
25-10-2011 03:30

Don't have cash to buy a car? Don't worry, just because this is available to take the mortgage loans to solve all the problems. Thence get a short term loan to buy everything you want.

Web  
Por: Heidi

Re: Hotlink protect
29-10-2011 16:06

paehkyqb{fnbo, oscetniwqr

Web  
Por: nzdvovqfvq

Re: Hotlink protect
29-10-2011 19:46

isgxxyqb{fnbo, ialngwnxjg

Web  
Por: nwfsizklft

Re: Hotlink protect
29-10-2011 23:04

qjjkoyqb{fnbo, oroqwyuiuz

Web  
Por: wofjlbbvep

Re: Hotlink protect
01-11-2011 19:28

Hotlink Blocker is an IIS plug-in that will protect your site from bad people stealing your traffic by directly linking to content on your server.

Web  
Por: 03009654670

Re: Hotlink protect
03-11-2011 21:05

qopijyqb{fnbo, dfhrvdkmsx

Web  
Por: eajncwhecr

Re: Hotlink protect
09-11-2011 14:45

oanotyqb{fnbo, vyvqogommd

Web  
Por: mgbeddesjc

Re: Hotlink protect
24-11-2011 19:58

Thanks for your great article! It continues to be very helpful. I hope that you’ll carry on posting your wisdom with us.

Web  
Por: Eye Beauty Reviews

Re: Hotlink protect
26-11-2011 15:30

crpkiyqb{fnbo, tyextlkopv

Web  
Por: sazzddvkry

Re: Hotlink protect
26-11-2011 19:43

zhanuyqb{fnbo, wupettavpz

Web  
Por: mbhpjepevl

Re: Hotlink protect
18-01-2012 12:06

This is an awesome article. You should write more often on this.

Web  
Por: Toner

Titulo:
Nombre:
Web:
Comentario:
RECENT:
POSTS
/
COMENTARIOS
/
IMAGENES
> Bobalicons! el 19/10/2007

> Nomad Soul el 13/10/2007

> Texto para web con cualquier fuente el 06/07/2007

> Dramatic Chipmunk!!! el 28/06/2007

> Vivens el 27/06/2007
CALENDARIO
2005
Diciembre
2006
Enero / Febrero / Marzo / Abril / Mayo / Junio / Julio / Agosto / Septiembre / Octubre / Noviembre / Diciembre
2007
Enero / Junio / Julio / Octubre
TAGS
/
CATEGORIAS
> links 45 veces
 
> web 30 veces
 
> xpazeman 22 veces
 
> video 19 veces
 
> musica 15 veces
 
> coñas 11 veces
 
> pixel 9 veces
 
> flash 9 veces
 
> friki 7 veces
 
> 3d 7 veces
 
PLAYLIST
UNKLE - Lawless
War Stories (2007)
UNKLE - Morning Rage
War Stories (2007)
UNKLE - Twilight (feat. 3D)
War Stories (2007)
UNKLE - Persons And Machinery (feat. Autolux)
War Stories (2007)
UNKLE - Mayday (feat. The Duke Spirit)
War Stories (2007)
UNKLE - Burn My Shadow (feat. Ian Astbury)
War Stories (2007)
UNKLE - Price You Pay
War Stories (2007)
UNKLE - Keys To The Kingdom (feat. Gavin Clark)
War Stories (2007)
UNKLE - Restless (feat. Josh Homme)
War Stories (2007)
UNKLE - Hold My Hand
War Stories (2007)
/
YOUTUBE
All Artwork (cc) Xpazeman.com. Check CC license below
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Spain License.