Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1] 2 3   Go Down

Author Topic: hotlinking to redirect to the page that contains the image  (Read 55216 times)

0 Members and 1 Guest are viewing this topic.

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
hotlinking to redirect to the page that contains the image
« on: September 26, 2013, 03:40:25 pm »

Hotlinking: when users find your image in Google Images they will be redirect to your gallery, to the page that contains that image. They can not save it directly from google. That brings a lot more traffic (visitors to your gallery) and they will proabibly remember your gallery.
If users keep saving the image directly from google, you will loose a lot of visitors.

Attention: will consume more server resources (CPU time and MySql time) because redirect.php needs to search the database for  the image name and find the id of the page for that image.

A smaller database may help. Small database ( make you database smaller) for less server resource: http://forum.coppermine-gallery.net/index.php/topic,77935.0.html

found in the forum tutorial do redirect to a image or a link but not to  the page that contains the image

I did this:

Code: [Select]

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?allvip.us [NC]   
RewriteRule \.(jpg|jpeg|png|gif)$ allvip.us/gallery/displayimage.php [NC,R,L]


what should I write on line 4 of the code to go to displayimage.php of the actual image?
« Last Edit: December 09, 2014, 01:00:44 pm by allvip »
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #1 on: September 27, 2013, 09:42:56 pm »

As displayimage.php always require a pid parameter, you need to query the database. Please post a link to the tutorial, maybe there's some information that helps us.
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #2 on: September 28, 2013, 03:03:24 pm »

I choosed to use a .htaccess rule from http://www.hongkiat.com/blog/smarter-way-to-prevent-image-hotlinking-with-htaccess/

 now I have this code in my htacees that redirects all goggle images to: http://www.allvip.us/no_hotlinking.html

Code: [Select]
RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?allvip.us [NC]   
RewriteRule \.(jpg|jpeg|png|gif)$ http://www.allvip.us/no_hotlinking.html [NC,R,L]


I would like the to redirect to the page that contains the image.
example when people click  View image and not visit page:

http://www.google.com/imgres?um=1&sa=N&biw=1024&bih=580&hl=en&tbm=isch&tbnid=Q6MCfgnUUesY4M:&imgrefurl=http://allvip.us/gallery/displayimage.php%3Falbum%3D57%26pid%3D10287&docid=uMldMOIWdHBynM&imgurl=http://allvip.us/gallery/albums/userpics/10001/angelina_jolie_000009.jpg&w=682&h=1024&ei=QdBGUoyYI4SPswb7yIF4&zoom=1&ved=1t:3588,r:7,s:0,i:102&iact=rc&page=1&tbnh=222&tbnw=148&start=0&ndsp=11&tx=87&ty=115

all the images to redirect to the page that has the image
to redirect to http://www.allvip.us/gallery/displayimage.php?album=57&pid=10287

do not know what to look for in the database
the database has exact links of every pictures or albums but I can not write a rule in .htaccess for every image.I have to many pictures.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #4 on: October 01, 2013, 04:31:51 pm »

I hadn't looked at the Wordpress plugin, but here's how my idea should work. Somebody tries to directly view your example picture, which is located at
Quote
http://www.allvip.us/gallery/albums/userpics/10001/angelina_jolie_000009.jpg

Now, you need to create an .htaccess rule which passes that information as parameter to a new script instead of your static HTML page, let's call it redirect.php. That script needs some simple code which queries the database to get the picture ID (pid) of the accessed image. It's easy, as Coppermine stores the picture's file path and name in the database (which you just passed to the script). In our example, the file's path would be
Code: [Select]
userpics/10001/and the file's name
Code: [Select]
angelina_jolie_000009.jpgwhich can be extracted with a regular expression or a combination of substr/strpos.

Now, a query like
Code: [Select]
SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE filepath = '{$filepath}' AND filename = '{$filename}'should return the pid and you can redirect the user to the intermediate-sized view. As I've currently no testbed where I can test this, I can just provide you this generic information. If you need code, please let me know and I'll create it as soon as possible.
Logged

allvip

  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Posts: 1362
Re: hotlinking to redirect to the page that contains the image
« Reply #5 on: October 02, 2013, 09:48:00 am »

I did paste your code in phpMyAdmin in the SQL and I got:

Code: [Select]
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '['TABLE_PICTURES']} WHERE filepath = '{$filepath}' AND filename = '{$filename}' ' at line 1



yes I do need code
thanks
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #6 on: October 04, 2013, 10:24:50 am »

Of course this code won't work, as the variables need to filled with values. I'll add a proper .htaccess rule to my testbed and create working code now.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #7 on: October 04, 2013, 10:52:10 am »

Adjust the last line of your .htaccess file to
Code: [Select]
RewriteRule ^(.*\.(jpg|jpeg|png|gif))$ http://www.allvip.us/redirect.php?$1 [NC,R,L]and use this code for redirect.php
Code: [Select]
<?php
define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');

$file $superCage->server->getEscaped('QUERY_STRING');
if (
strpos($file$CONFIG['fullpath']) === FALSE) {
    
header("Location: no_hotlinking.html");
} else {
    
$file str_replace($CONFIG['fullpath'], ''$file);
    
$pos strrpos($file'/') + 1;
    
$filepath substr($file0$pos);
    
$filename substr($file$pos);
    
$pid mysql_result(cpg_db_query("SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE filepath = '{$filepath}' AND filename = '{$filename}' LIMIT 1"), 0);
    if (
$pid) {
        
header("Location: displayimage.php?pid=".$pid);
    } else {
        
header("Location: no_hotlinking.html");
    }
}
« Last Edit: July 23, 2014, 12:27:08 pm by Αndré »
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #8 on: October 04, 2013, 04:57:41 pm »

Hello André,

I have a question,

Would not it be necessary to consider also $CONFIG['url']?

Regards.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #9 on: October 04, 2013, 06:42:47 pm »

That code worked in my testbed, as the query string just returned "albums/.../...".
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #10 on: October 04, 2013, 09:51:22 pm »

Hello André,

I replaced "no_hotlinking.html" with an image file and always redirects to the image, never to the intermediate page.

I have verified that everything is correct as you wrote the code.

Regards.
« Last Edit: October 04, 2013, 10:26:24 pm by Niecher »
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #11 on: October 05, 2013, 01:51:26 pm »

Please post an example link to an intermediate-sized image in your gallery.
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #12 on: October 05, 2013, 02:39:58 pm »

Hello André,

I am now using another hotlinking until I can use yours. I think your hotlinking will be very good.
An example here, and I'm using this.

Regards.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #13 on: October 07, 2013, 04:20:54 pm »

http://wonmyo.com/albums/uploads/Logotipos/thumb_acdc_logo.png shows the image
http://wonmyo.com/albums/uploads/Logotipos/normal_acdc_logo.png shows the image
http://wonmyo.com/albums/uploads/Logotipos/acdc_logo.png redirects to http://wonmyo.com/direct-linking-not-permitted.jpg

Keep in mind that your browser may load images from cache, which will skip the .htaccess rule.

I currently don't know what exactly
I replaced "no_hotlinking.html" with an image file and always redirects to the image, never to the intermediate page.
means. Do you get redirected to your "no_hotlinking.html" image file replacement or do you get the result as above?
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #14 on: October 07, 2013, 04:41:42 pm »

Hello André,

In your code I replaced:
Code: [Select]
header ("Location: direct-linking-not-permitted.jpg");instead of
Code: [Select]
header ("Location: no_hotlinking.html");
Always redirects to the image and I hope to be redirected to the intermediate page:
Code: [Select]
header("Location: displayimage.php?pid=".$pid);
Regards.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #15 on: October 07, 2013, 05:09:24 pm »

Please try again with this code for redirect.php and post the result:
Code: [Select]
<?php
define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');

echo 
$superCage->server->getEscaped('QUERY_STRING');
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #16 on: October 08, 2013, 01:33:11 am »

This new has the same behavior as above, redirects to hotlink image but not to the intermediate image page.

I tried this one too, and nothing:
Code: [Select]
echo $superCage->server->getEscaped('QUERY_STRING', '/^[a-zA-Z0-9&=_\/.-]+$/');


Regards.
« Last Edit: October 08, 2013, 01:53:27 am by Niecher »
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #17 on: October 08, 2013, 09:12:25 am »

It's not possible that the script redirects you, as it just prints the query string, nothing more. Please post the content of your .htaccess file.
Logged

Niecher

  • LocalSupporter
  • Coppermine frequent poster
  • ***
  • Country: es
  • Offline Offline
  • Gender: Male
  • Posts: 191
Re: hotlinking to redirect to the page that contains the image
« Reply #18 on: October 08, 2013, 09:23:24 am »

Hello André,

I did above, is this. Anyway I also used htacces content posted above by allvip and with the new rule rewritte said by you to this file redirect.php.

I made sure to try following his instructions.

Regards.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: hotlinking to redirect to the page that contains the image
« Reply #19 on: October 08, 2013, 09:34:30 am »

I still don't know if you adjusted your .htaccess file properly. That's why I asked to post the current content.
Logged
Pages: [1] 2 3   Go Up
 

Page created in 0.052 seconds with 19 queries.