Bandwidth stealing block

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Bandwidth stealing block

Post by codewarrior »

Wasn't sure where to post this ... but here I'm :lol:

I'm looking for some code that would block bandwidth stealing... you know what people like pic on your site and use them on other sites or make a file linkable to other site without telling you ... hence the term Bandwidth stealing :D

Anyone know any code on it? or could guide me in the right direction. ;)

THanks a million! :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post by codewarrior »

Danke schön!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

de rien ;)
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I don't know German.... BUt I can speak Japanese lol! :D

Can't you do this with PHP cos I can't edit Apache since it's not my own wb server...

doumo :wink:
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

you could use something like:

last link = the link the user clicked before getting to the current page..

"if the last link = part of your site address then show image/file, else print error msg...."

does it make any sense? if it does't then i will make a script it to show what i mean :/
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

yeah just do a conditional on the referal url.... if it aint you they dont get the piccy
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

But you can't do it to an image...
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

why not? you only need a part of your own url, this could be sitename.com
forget the rest....
sinewave
Forum Commoner
Posts: 41
Joined: Tue Sep 10, 2002 4:35 pm
Location: Canada

Post by sinewave »

how would that actually stop someone from hotlinking it? how would you specify all pictures..and not block them from linking to you directly
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Sorry forgot to say

Can't block images with PHP...
ShrineMaster
Forum Newbie
Posts: 7
Joined: Mon May 20, 2002 5:33 am

Post by ShrineMaster »

Images are easy to block with php, just never link directly to the images on your own site and feed them through a PHP script that checks the referer.

Since some browsers don't send refering information to the server you only want to apply your referer check to those that actually show the referer.

Also when you do your referer check, make sure that the host name is located in the correct part of the refering url. if you don't check that, something like:
http://www.somesite.com/page.html?http: ... rpage.html
will show your images. I found this out when I noticed archives of my site on google were loading images off my server.

Code: Select all

if ($HTTP_REFERER) {
	$referer = strtolower($HTTP_REFERER);
	$host = strtolower($HTTP_HOST);
	if (strpos($referer, "http://$host") != 0 || !stristr($referer, "http://$host")) {
		readfile("./images/dontlinktothis.jpg");
		exit;
	}
}
Use the header() functions to tell the browser it is an image and use readfile() to pass the image data through.
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post by codewarrior »

Yeah Images are easy, its the dang Files that people keep on stealing. I wouldn't mind if they just asked. But NO! They have to go out and be sneeky! I hate that! :x I'll try the code which was proposed. I hope it works coz BHD's Demo come out tomorrow! 8O :lol:
codewarrior
Forum Commoner
Posts: 81
Joined: Wed Aug 07, 2002 1:28 pm

Post by codewarrior »

qads wrote:you could use something like:

last link = the link the user clicked before getting to the current page..

"if the last link = part of your site address then show image/file, else print error msg...."

does it make any sense? if it does't then i will make a script it to show what i mean :/
<====== Complete N00B here! :lol: Went over me head! Would really appreciate a script ;) Thanks in advance. :)
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

if ($HTTP_REFERER) {
$referer = $HTTP_REFERER;
$host = "your.site";

if ($referer == '$host')
{
print("image, text, link to download file etc");
}
else
{
print("this is stealing!");
}
}

it is soemthing like that :/

if you put $host in a array and loop with each(); then you can have more then 1 domain allowed to load the files :)

i don't think the above code will work cos i have't tested it, but you should get the idea...
Post Reply