hotlinking to redirect to the page that contains the image hotlinking to redirect to the page that contains the image
 

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]

Main Menu

hotlinking to redirect to the page that contains the image

Started by allvip, September 26, 2013, 03:40:25 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

allvip

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:



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?

Αndré

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.

allvip

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


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.


Αndré

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
Quotehttp://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
userpics/10001/
and the file's name
angelina_jolie_000009.jpg
which can be extracted with a regular expression or a combination of substr/strpos.

Now, a query like
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.

allvip

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


#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

Αndré

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.

Αndré

Adjust the last line of your .htaccess file to
RewriteRule ^(.*\.(jpg|jpeg|png|gif))$ http://www.allvip.us/redirect.php?$1 [NC,R,L]
and use this code for redirect.php
<?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");
    }
}

Niecher

Hello André,

I have a question,

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

Regards.

Αndré

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

Niecher

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.

Αndré

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

Niecher

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.

Αndré

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
Quote from: Niecher on October 04, 2013, 09:51:22 PM
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?

Niecher

Hello André,

In your code I replaced:
header ("Location: direct-linking-not-permitted.jpg");
instead of
header ("Location: no_hotlinking.html");

Always redirects to the image and I hope to be redirected to the intermediate page:
header("Location: displayimage.php?pid=".$pid);

Regards.

Αndré

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

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

Niecher

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:

echo $superCage->server->getEscaped('QUERY_STRING', '/^[a-zA-Z0-9&=_\/.-]+$/');



Regards.

Αndré

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.

Niecher

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.

Αndré

I still don't know if you adjusted your .htaccess file properly. That's why I asked to post the current content.