hotlinking to redirect to the page that contains the image - Page 2 hotlinking to redirect to the page that contains the image - Page 2
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

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.

Niecher

Ahh Ok

For the plugin sef_url

I'm going to uninstall, I'll try without plugin, that I did not try.

Niecher

Hello André,

I tested clean, without htaccess and without sef_url plugin.

It seems that does not work on my server. I see no need to disturb more.

With hotlink image is enough for me.

Thank you so much, always.

Αndré


Niecher

Thank you very much Master,

There was a conflict with the plugin sef_url (removed).

Working perfectly 100%, first script you created, here

This htaccess file is ready for redirect.php script, as follows:


<Files ".htaccess">
Order Allow,Deny
Deny from All
</Files>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f

RewriteCond %{REQUEST_FILENAME} \.([Bb][Mm][Pp]|[Jj][Pp][Ee]?[Gg]|[Gg][Ii][Ff]|[Pp][Nn][Gg])$ [NC]

<FilesMatch "^(normal_(.*)|thumb_(.*)).([Bb][Mm][Pp]|[Jj][Pp][Ee]?[Gg]|[Gg][Ii][Ff]|[Pp][Nn][Gg])$">
RewriteCond %{HTTP_REFERER} !^$
</FilesMatch>

RewriteCond %{HTTP_REFERER} !^http(s)?://(.*)?example.com [NC]

RewriteCond %{REQUEST_URI} !^/example\.jpg$ [NC]

RewriteRule ^(.*\.([Bb][Mm][Pp]|[Jj][Pp][Ee]?[Gg]|[Gg][Ii][Ff]|[Pp][Nn][Gg]))$ http://example.com/redirect.php?$1 [R,NC,L]

RewriteCond %{REQUEST_FILENAME} -f

RewriteCond %{REQUEST_FILENAME} \.(7z|aac|arj|as(f|x)|avi|bz2|divx|docx?|f4(a|v)|flv|gtar|gz|lzh|m4(a|v)|midi?|mkv|mov(ie)|mp(2|3|4|e?g)|og(g|m)|pdf|qt|ra(m|r)|sw(c|f)|tar|tgz|wm(a|v)|zip)$ [NC]

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http(s)?://(.*)?example.com [NC]

RewriteRule ^(.*\.(7z|aac|arj|as(f|x)|avi|bz2|divx|docx?|f4(a|v)|flv|gtar|gz|lzh|m4(a|v)|midi?|mkv|mov(ie)|mp(2|3|4|e?g)|og(g|m)|pdf|qt|ra(m|r)|sw(c|f)|tar|tgz|wm(a|v)|zip))$ http://example.com/redirect.php?$1 [R,NC,L]



Note: To be used in the root folder. Do not forget to replace example.com with your domain and example.jpg your image to redirect.

This other htaccess file does not work with redirect.php, is a different file (free choice, what each one likes).

Regards.

allvip

Quote from: Αndré on October 04, 2013, 10:52:10 AM
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}'"), 0);
    if (
$pid) {
        
header("Location: displayimage.php?pid=".$pid);
    } else {
        
header("Location: no_hotlinking.html");
    }
}



thanks a lot.it worked.
I only edited a little the code for the .htaccess:



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



because my gallery is not at allvip.us  is in the folder gallery -  allvip.us/gallery
I placed the .htaccess , redirect.php and no_hotlinking.html in the gallery folder.

allvip

In created a new .htaccess in the gallery folder only with your code and my original .htaccess with other website rules is still in the public_html

Niecher

Hello allvip,

Thank you very much for your idea and request, this is a good hotlinking.

Regards.

allvip

even more thanks to andre that took the time to make it
thanks andre for the code is VERY, VERY  important to a website.

allvip

If anyone wants all the gallery pages to redirect from example.com to www.example.com (useful for CloudFlare.CloudFlare has no point if users access the site without www.
CoudFlare runs only for www.)

code by Andre Reply #14:

http://forum.coppermine-gallery.net/index.php/topic,77210.0.html


allvip

Redirect.php is making the CPU time and MySQL time very hight.

Greg told me:

This will result in a full scan of the cpg pictures table for every request because:

    There is no index available that MySQL can use to find the result based on filepath and filename.
    There is no information given to MySQL to allow it to stop after the first (and ONLY) match is found - it will complete the scan...

For the second issue - just adding 'LIMIT 1' to the SQL statement will tell MySQL to stop looking after the first match... We know there can only be one match (the same filepath/filename can only exist once - but MySQL doesn't know that...)

For the first issue - we need to add some kind of index. The perhaps obvious choice would be a 2 column unique index on filepath and filename. Unfortunatly we hit a MySQL limitation of 1000 byte key... Both filepath and filename at defined as varchar(255) - or 510 characters - but when saved in UTF8 - can take up to 3 bytes per character - which exceeds the limit.
We can reduce the amount of data in the index - or take an approach with 1 column index(es).

I would suggest adding the following index (via phpMyAdmin) using your correct cpg table prefix - expecting that in most cases your actual fieldlengths are smaller than 255...:

ALTER TABLE `cpg_pictures`  ADD UNIQUE `filepath_filename` (`filepath` (200), `filename` (100))

and changing the SQL statement to:

SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE filepath = '{$filepath}' AND filename = '{$filename}' LIMIT 1

allvip

In phpMyAdmin I clicked the coppermine database - click SQL button on top - click clear - paste ALTER TABLE ... - click Go.

Error

SQL query:

ALTER TABLE `cpg15x_pictures`  ADD UNIQUE `filepath_filename` (`filepath` (200), `filename` (100))

MySQL said: Documentation
#1061 - Duplicate key name 'filepath_filename'

with:


ALTER TABLE `cpg15x_pictures`  ADD INDEX `filename` (`filename`)


Error
SQL query:

ALTER TABLE `cpg15x_pictures`  ADD INDEX `filename` (`filename`)

MySQL said: Documentation
#1061 - Duplicate key name 'filename'


allvip

I can not even tell if the database is optimize.
Is proabibly not a coppermine dev problem,but please help.

How to optimize the database or just the cpg pictures table?
How to make redirect.php take less resources?

allvip

I can give my host cpanel password to Greg,Andre or Jeff Bailey.

Αndré

Quote from: allvip on July 22, 2014, 06:37:41 PM
ALTER TABLE `cpg15x_pictures`  ADD UNIQUE `filepath_filename` (`filepath` (200), `filename` (100))

MySQL said: Documentation
#1061 - Duplicate key name 'filepath_filename'

I assume you try to add the index more than once? If so, that error message is obvious. I just applied both queries on my Coppermine database successfully.

allvip

How can I tell if the pictures table is indexed now?

allvip

Quote from: Αndré on July 23, 2014, 10:20:39 AM
I assume you try to add the index more than once?

Yes.Twice.
The first time the error was:

Error
SQL query:

ALTER TABLE `cpg15x_pictures`  ADD UNIQUE `filepath_filename` (`filepath` (200), `filename` (100))

MySQL said: Documentation
#1062 - Duplicate entry 'userpics/10001/-barbara_palvin_8.jpg' for key 'filepath_filename'

I deleted -barbara_palvin_8.jpg and tryed again.

Αndré


allvip


Αndré


allvip

Can you please,please help me index all the tables.
Is important for the database to use less server resources.
Is the default coppermine database.Nothing changed.
I belive all the copermine databases look the same.