Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-2007, 06:45 PM
elle elle is offline
Newbie
 
Join Date: May 2007
Posts: 10
Rep Power: 0
elle is on a distinguished road
Post Protection JPEG/DIR with session

Hi,
I need some help/ideas with this : I'm using session for user's authorization and need to access "private" image data or access to some directory for authorized user only. My question is how to protect images (image file or directory) with session (I mean no HTTP basic authentication scheme is allowed) ?

I've tried something like this, but it doesn't work properly probably due to the directory rights.

Code:
<?php

function LoadJpeg($imgname)
{
    $im = @imagecreatefromjpeg($imgname);
    if (!$im) { /* See if it failed */

        /* Output an errmsg */

    }
    return $im;
}

/* if (user logged in) */

header("Content-Type: image/jpeg");
$img = LoadJpeg("private/image.jpg");
imagejpeg($img);

?>
Some ideas how it's done would be appreciated.
TIA

Last edited by elle; 07-19-2007 at 06:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-20-2007, 05:58 PM
Crane's Avatar   
Crane Crane is offline
Programming Expert
 
Join Date: Nov 2005
Posts: 399
Rep Power: 14
Crane is on a distinguished road
Default

And the code above doesn't work? If the user is logged in allow them to access it. If not redirect them. Seems like a solid plan.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-21-2007, 07:00 PM
elle elle is offline
Newbie
 
Join Date: May 2007
Posts: 10
Rep Power: 0
elle is on a distinguished road
Default

Actually the code above is really correct. Some modification can be still applied I mean replace creatimage function with some direct stream read function (avoiding of compression) but this still doesn't solve the image protection in the directory. The solution is to use .htaccess on it with deny to show images.

That's it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-22-2007, 12:39 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

I've never used the deny feature in .htaccess. Is that the same method for hotlink protection - if so, can you deny yourself from accessing them?

You could always store your images outside the public_html folder and use GD to generate the images as you need them.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-22-2007, 03:14 PM
elle elle is offline
Newbie
 
Join Date: May 2007
Posts: 10
Rep Power: 0
elle is on a distinguished road
Default

Actually I'm using some freeweb hosting and there's no way how to access directory out of the web root. So .htaccess works pretty well for me now.

I'm using this one inside the image folder:

Code:
<FilesMatch "\.(jp?g)$">
   order deny,allow
   deny from all
</FilesMatch>
For reading image data from php is used fpassthru() function or something like that. Now I can decide who's authorized via session and provide the image.

elle
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
trademark or copyright protection Masterguns Business and Legal 3 10-20-2007 01:07 PM
Keyboard Protection for Laptops kseine Computer Hardware 1 06-14-2007 09:04 AM
object in session.... "<logic:present>" with JSTL? reachpradeep Java Help 0 03-04-2007 09:46 AM


All times are GMT -5. The time now is 05:06 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads