To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-01-2003, 03:30 AM   #1
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
Hot Link Prevention

Hey here is a piece of GPL code that I just finished packaging up.

It's a hot link prevention scheme implemented entirly in php.

I know it's pretty easy to get around:
::coughhiddenframescough::
::coughpopupscough::

The main things I'm interested in are
1) did I do the gpl stuff right, it's my first time using it.
2) is there a stronger way to do this in php?
drawmack is offline   Reply With Quote
Old 11-01-2003, 03:31 AM   #2
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
forgot to attach the file here it is
Attached Files
File Type: zip ewd_hlp_10.zip (30.2 KB, 83 views)
drawmack is offline   Reply With Quote
Old 11-01-2003, 02:58 PM   #3
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
why do you die() after setting the hotlink image? do you not want it output?
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 11-01-2003, 03:10 PM   #4
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
sometimes the only response I have is ooppss. Anyway here is the fixed version.
Attached Files
File Type: zip ewd_hlp_10.zip (30.1 KB, 81 views)
drawmack is offline   Reply With Quote
Old 11-02-2003, 09:33 PM   #5
bigray
Senior Member
 
Join Date: Aug 2002
Location: usa
Posts: 144
what does this script do?
bigray is offline   Reply With Quote
Old 11-02-2003, 11:05 PM   #6
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
It is a weak form of hot link prevention.

one of the scripts sets a session variable.

the other script checks for the existence of this session variable before spitting out the file that was requested. If the session variable does not exist then the second script spits out a file that displays hot linker on the person's screen instead of the requested file.

It is weak due to the use of session variables. I have another one written that uses $_SERVER['HTTP_REFERER'] instead which is a bit stronger but could fail if the http_referer is blank for any reason. I'll be working up a third version in the near future that puts both methods together. It is for a series of articles for my web site.
drawmack is offline   Reply With Quote
Old 11-04-2003, 01:14 AM   #7
bigray
Senior Member
 
Join Date: Aug 2002
Location: usa
Posts: 144
Cool man,
do you have a login script, like say someone is not a member on your site.
Any link he clicks it well say something like "Hey guest, click here to login, etc"? Where can i get a script like this or do you already have one? Thanks bro.
bigray is offline   Reply With Quote
Old 11-04-2003, 01:34 AM   #8
BuzzLY
2($infinity) && $beyond
 
BuzzLY's Avatar
 
Join Date: Nov 2002
Location: Star Command
Posts: 2,535
As was pointed out to you earlier, this is off topic, and off forum. I split your question to the General Help forum, to this thread.

Let's keep this forum and its threads for code critique only, ok?
__________________
New to the board? Check out the guidelines
| Color Picker | Blogification |
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
With all its sham, drudgery, and broken dreams, it's still a beautiful world.
BuzzLY is offline   Reply With Quote
Old 11-24-2003, 01:19 PM   #9
KITTfan2K
Farscape Rules!
 
KITTfan2K's Avatar
 
Join Date: Oct 2002
Location: Uncharted Territories
Posts: 119
There's probably a simpler way to do this:

PHP Code:
<?php

if (($File != @fopen ($_GET['File'], "br") || strpos($HTTP_REFERRER, $MySiteName) === false))
// If the file can't be opened, or the http_referrer is not from your site.
{
   
// Open the 'NotFound' file and change the filesize accordingly
   
$FileLength = filesize("Images/NotFound.gif");
   
$File = fopen ("Images/NotFound.gif");
   
// The 'notFound' file had better exist, otherwise the image will show as a red X!
}
else
{
   
// get the filesize of the file that we're loading
   
$FileLength = filesize($_GET['File']);
}

$File2 = fread($File, $FileLength);
fclose ($File);
// Get the contents of the file and then close it.

echo $File;
// print out the contents of the file.

?>
This is just something that I came up with off the top of my head to do a similar thing.

edit: this is probably riddled with errors, I didn't check anything on the PHP manual before I posted, but the comments should give you the general idea.

KITTfan2K

Last edited by KITTfan2K; 11-24-2003 at 01:27 PM.
KITTfan2K is offline   Reply With Quote
Old 11-24-2003, 05:45 PM   #10
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
Kitt: http://www.suryvial.com/articles/1/3
drawmack is offline   Reply With Quote
Old 12-06-2003, 04:55 PM   #11
liquidmotion
Junior Member
 
Join Date: Dec 2003
Posts: 3
what we do is, have the page that SHOULD HAVE refered it set a session or other variable. if this variable isn't present/correct when the user tries to download the file, deny access.
liquidmotion is offline   Reply With Quote
Old 12-07-2003, 01:49 AM   #12
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
That is way easy to hack:

Here is an overview of the protocol you're using:

Page A --> Sets session variable
Page B --> Reads session variable and (dis)allows access accordingly.


Here is the hack

Page C --> frames page with Page A in a hidden frame
Page D --> loads your image and the session variable is set.

Last edited by drawmack; 12-07-2003 at 01:52 AM.
drawmack is offline   Reply With Quote
Old 12-07-2003, 01:51 AM   #13
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
what do backticks have to do with hotlink prevention and sessions?
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 12-07-2003, 01:53 AM   #14
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
moon, I had to change the batteries in my keyboard and the submit was accidental I've fixed it now.
drawmack is offline   Reply With Quote
Old 12-07-2003, 02:07 AM   #15
liquidmotion
Junior Member
 
Join Date: Dec 2003
Posts: 3
Quote:
Originally posted by drawmack
That is way easy to hack:

Here is an overview of the protocol you're using:

Page A --> Sets session variable
Page B --> Reads session variable and (dis)allows access accordingly.


Here is the hack

Page C --> frames page with Page A in a hidden frame
Page D --> loads your image and the session variable is set.
are your files really worth saving that badly? if they go to this much trouble to "hack" it, they are going to get it.

i guess.
liquidmotion is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 11:29 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.