Bluehost.com Web Hosting $6.95

Stop hotlinking to a specific file & keeping a counter

This is a discussion on Stop hotlinking to a specific file & keeping a counter within the PHP Language forums, part of the PHP Programming Forums category; Hi, How can I stop hotlinking to a specific file, and I want it to redirect it to a PHP ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-25-2008
Adhal
 
Posts: n/a
Default Stop hotlinking to a specific file & keeping a counter

Hi,
How can I stop hotlinking to a specific file, and I want it to redirect it to a PHP link so I
can monitor the number of downloads.

Here is my site with the download page:
http://www.adhal.org/software/downloads.htm

And here is softpedia directly connecting to my file and bypassing the counter php.
http://www.softpedia.com/get/File-ma.../HashNET.shtml

I am new to this, so excuse the ignorance. I do plan to read on it sooner or later. :)

I have seen examples of it using the .htaccess, but it deals with mimes. I want actually stop
hotlinking to a specific file which I want to redirect to another specified link (My PHP Counter link).

Thanks for taking time to look a this

--
Adhal Freeware
http://www.adhal.org
Reply With Quote
  #2 (permalink)  
Old 06-25-2008
Captain Paralytic
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

On 25 Jun, 15:05, Adhal <f...@email.com> wrote:
> Hi,
> * * How can I stop hotlinking to a specific file, and I want it to redirect it to a PHP link so I
> can monitor the number of downloads.
>
> Here is my site with the download page:http://www.adhal.org/software/downloads.htm
>
> And here is softpedia directly connecting to my file and bypassing the counter php.http://www.softpedia.com/get/File-ma.../HashNET.shtml
>
> I am new to this, so excuse the ignorance. I do plan to read on it sooneror later. :)
>
> I have seen examples of it using the .htaccess, but it deals with mimes. I want actually stop
> hotlinking to a specific file which I want to redirect to another specified link (My PHP Counter link).
>
> Thanks for taking time to look a this
>
> --
> Adhal Freewarehttp://www.adhal.org


You could change the location of your file and use .htaccess to map
the current file name to your php script, which would at its end,
deliver the real file as payload.
Reply With Quote
  #3 (permalink)  
Old 06-25-2008
John Smith
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

>> --
>> Adhal Freewarehttp://www.adhal.org

>
> You could change the location of your file and use .htaccess to map
> the current file name to your php script, which would at its end,
> deliver the real file as payload.


Thanks but ahem, I don't know how to that. Would URLBar display the actual location of the file?


In truth I would prefer it, if the HTTP_REFERER is not from

http://www.adhal.org/software/downloads.htm
or
http://www.adhal.org/ccount/click.php?id=1

Then redirect it to

http://www.adhal.org/ccount/click.php?id=1

So I don't have to worry if they actually get access to the correct file path. I am I gave softpedia
my PHP link, but they connected directly to my file.

Or a better way is a cgi-script that monitors all file access. That would be cool, but I have no
clue if it is possible. I am new to web creation and trying to feel my way around.
Reply With Quote
  #4 (permalink)  
Old 06-25-2008
Adhal
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

John Smith is the me also. I should remove that card
--
Adhal Freeware
http://www.adhal.org
Reply With Quote
  #5 (permalink)  
Old 06-25-2008
Álvaro G. Vicario
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

Adhal escribió:
> How can I stop hotlinking to a specific file, and I want it to
> redirect it to a PHP link so I
> can monitor the number of downloads.
>
> Here is my site with the download page:
> http://www.adhal.org/software/downloads.htm
>
> And here is softpedia directly connecting to my file and bypassing the
> counter php.
> http://www.softpedia.com/get/File-ma.../HashNET.shtml
>
> I am new to this, so excuse the ignorance. I do plan to read on it
> sooner or later. :)
>
> I have seen examples of it using the .htaccess, but it deals with mimes.
> I want actually stop
> hotlinking to a specific file which I want to redirect to another
> specified link (My PHP Counter link).


If your web server is Apache and you want a transparent redirect then
you can use mod_rewrite. If the link is...

http://www.adhal.org/files/HashNET.zip

.... you can create an .htaccess file inside "files" with something like:

RewriteEngine On

RewriteBase /
RewriteRule ^HashNET\.zip$ path/to/counter.php?param=whatever [NC,L]


The exact rule depends on how counter.php works but this should give you
an idea.





--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Reply With Quote
  #6 (permalink)  
Old 06-25-2008
Captain Paralytic
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

On 25 Jun, 16:13, John Smith <u...@example.net> wrote:
> >> --
> >> Adhal Freewarehttp://www.adhal.org

>
> > You could change the location of your file and use .htaccess to map
> > the current file name to your php script, which would at its end,
> > deliver the real file as payload.

>
> Thanks but ahem, I don't know how to that. Would URLBar display the actual location of the > file?

Sorry, in future I will only answer your questions with answers that
you already know, will that help?
I would send the payload using readfile(), so the browser would
continue to show the address that was linked to.

>
> In truth I would prefer it, if the HTTP_REFERER is not from

You may prefer that, but since HTTP_REFERER is not reliable (indeed
not always set), you've dipped.

Reply With Quote
  #7 (permalink)  
Old 06-25-2008
Adhal
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

Álvaro G. Vicario wrote:
like:
>
> RewriteEngine On
>
> RewriteBase /
> RewriteRule ^HashNET\.zip$ path/to/counter.php?param=whatever [NC,L]
>
>
> The exact rule depends on how counter.php works but this should give you
> an idea.


Thanks Álvaro, works a treat. :)


--
Adhal Freeware
http://www.adhal.org
Reply With Quote
  #8 (permalink)  
Old 06-25-2008
Adhal
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

Captain Paralytic wrote:
> Sorry, in future I will only answer your questions with answers that
> you already know, will that help?



I am new to web creation so I was expecting a bit more detail or link. Anyhow, thanks for your reply.

--
Adhal Freeware
http://www.adhal.org
Reply With Quote
  #9 (permalink)  
Old 06-25-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

Adhal wrote:
> Captain Paralytic wrote:
>> Sorry, in future I will only answer your questions with answers that
>> you already know, will that help?

>
>
> I am new to web creation so I was expecting a bit more detail or link.
> Anyhow, thanks for your reply.
>


Welcome to the world of web programming! :-) Yes, we do get a little
terse here sometimes. We don't know how experienced you are, and it
saves what could be a lot of unnecessary typing (and our time).

Two things. First of all, if at all possible, place the file outside of
your DOCUMENT_ROOT (the root directory of your web server). Many
hosting companies allow you to have files and/or directories above the
root directory, i.e.


mysite
html otherdir

In a case like this, you would upload your web files to mysite/html, and
this would be the root directory of your website. You could place other
files in mysite, or create another directory mysite/otherdir to store
the files (my preference).

Now, any files in mysite/otherdir will be inaccessible directly from the
internet. But you can use readfile() to access the file, i.e. if the
file were "myfile.html",

readfile($_SERVER['DOCUMENT_ROOT'] . '/../otherdir/myfile.html');

($SERVER['DOCUMENT_ROOT'] always points at the root directory of your
webserver, then you go up one directory and down to otherdir).

This would go in the page with your counter; besides incrementing the
counter, it will send the file to the user. The only other thing you
need to do is set the correct content - see the header() function for
info on this.

However, there is an easier way than all this. You should have access
to the web server's logs for your site (good hosting companies will
provide this). You can see directly from the logs exactly how many
times the file has been downloaded.

However, remember one thing - these counters are not accurate. A file
or page may be cached by any server between you and the user, and the
file/page served from the cache. This cuts down on internet traffic,
but means you won't see the request.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #10 (permalink)  
Old 06-25-2008
Adhal
 
Posts: n/a
Default Re: Stop hotlinking to a specific file & keeping a counter

Jerry Stuckle wrote:
>
> However, remember one thing - these counters are not accurate. A file
> or page may be cached by any server between you and the user, and the
> file/page served from the cache. This cuts down on internet traffic,
> but means you won't see the request.


Thanks Jerry. I really do appreciate the input.

I am totally new to PHP, and other web scripting languages; I am coming
for windows application developer.

I do plan to study it, as soon as I get C# and .NET framework out of the
way. I already know a bit of HTML, XHTML and CSS. My level of server
scripting is about zero, I tend to do a hatch job of it.

Just out of curiosity what would you recommend the study path I take.
Once I have time I am thinking of delving deeper into HTML, XHTML, CSS
and then PHP.

I don't think I will study Perl or any other scripting language
(excluding ASP.NET). From my understanding PHP is all one needs for a
personal site hosted on linux.

--
Adhal Freeware
http://www.adhal.org
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:21 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0