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 |
30-08-2006 15:39
clap clap clap clap
brutal !!!!!! :D
30-08-2006 16:20
Grazze grazze, se hace lo que se puede.
:)
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
14-01-2008 06:12
Ya lo tengo en funcionamiento en mi pagina web, es excelente!!
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 ;)
21-05-2008 10:37
Me alegro mucho de que te haya servido. ¡Gracias por el comentario!
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.
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!
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.
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.
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.
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.
20-06-2011 18:03
Your blog is absolutely fantastic! Lots of great information and inspiration, both of which we all need!
26-06-2011 14:49
Everybody loves bon bons! Cheers from France
27-06-2011 14:01
Your post is very good and design are very awesome i really like it. Thanks a lot!!!
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.
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!
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!
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!
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.
13-08-2011 10:18
It's such a terrific post, that I've forwarded it to my friends!
Tax Return
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.
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.
25-08-2011 16:31
opbmvyqb{fnbo, ptfxuqptts
30-08-2011 08:38
Very interesting and informative article indeed. I have to admit that I always follow all news about this.
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.
05-09-2011 15:32
Your post is very good and design are very awesome i really like it. Thanks a lot!!!
07-09-2011 19:11
Your blog is absolutely fantastic! Lots of great information and inspiration, both of which we all need!
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.
21-09-2011 15:07
pspxyyqb{fnbo, ioygwkpuqx
06-10-2011 15:35
yholeyqb{fnbo, vyjvozqtqy
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
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!
18-10-2011 21:58
lyqxiyqb{fnbo, kfuxedatff
19-10-2011 14:32
Great post.Can i Share it with my friends?
20-10-2011 15:12
woxjfyqb{fnbo, fldjryajnc
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
21-10-2011 04:20
ddbgkyqb{fnbo, obesosfjjp
21-10-2011 08:24
hhrmpyqb{fnbo, eeuxhvxvxx
21-10-2011 12:22
ptkhryqb{fnbo, thgzcetlzy
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
23-10-2011 07:54
nice information provided, news and entertaiment
23-10-2011 21:18
tvepbyqb{fnbo, ysvrxnikpx
24-10-2011 01:07
xutcdyqb{fnbo, kwmzysmlpl
24-10-2011 04:57
tgbjlyqb{fnbo, mlotyptbmf
24-10-2011 08:44
qhpnlyqb{fnbo, xoauwwjbpq
24-10-2011 12:36
jveonyqb{fnbo, ablexdvvpx
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.
29-10-2011 16:06
paehkyqb{fnbo, oscetniwqr
29-10-2011 19:46
isgxxyqb{fnbo, ialngwnxjg
29-10-2011 23:04
qjjkoyqb{fnbo, oroqwyuiuz
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.
03-11-2011 21:05
qopijyqb{fnbo, dfhrvdkmsx
09-11-2011 14:45
oanotyqb{fnbo, vyvqogommd
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.
26-11-2011 15:30
crpkiyqb{fnbo, tyextlkopv
26-11-2011 19:43
zhanuyqb{fnbo, wupettavpz
18-01-2012 12:06
This is an awesome article. You should write more often on this.