473,471 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP Security Issue

228 New Member
Hi,
Sorry if this question has been asked before. I am doin a website that requests users to upload their photos, articles. I put those in a folder outside the root folder of my website. But the visitor can easily see the folders they r located in by viewin the src of the html. How can i sort of encypt that? What security measures should I take to protect those datas basically?

NOTE: I am a newbie n this is a project i am tryin to finish successfully.
Oct 5 '08 #1
6 1393
Markus
6,050 Recognized Expert Expert
If they're outside of the webroot, ie:

Expand|Select|Wrap|Line Numbers
  1. - host
  2. - safe
  3.     - user_photos
  4.     - user_articles
  5. - web_root(html)
  6.      index.php
  7.  
where safe is the location of user_photos and user_articles, it shouldn't matter whether the user can see the location of the files because they're stored somewhere where they are inaccessible to the browser.

If I am misunderstanding, please correct me.

Markus.
Oct 5 '08 #2
bnashenas1984
258 Contributor
Hi
The problem is that if you don't allow the user to have access to an image then you can not use the image in a HTML because the user will still need access to view it.

But there is one thing I could come up with to protect images.

Put your images in a folder which users don't have access to. Then you can use PHP GD to serve the image only to a specified user.

Here is the code to serve the image by PHP GD:
imageviewer.php
Expand|Select|Wrap|Line Numbers
  1. <?PHP 
  2.     // if the image in a GIF use imagecreatefromgif 
  3.     // if the image in a PNG use imagecreatefrompng 
  4.  
  5.     $img=imagecreatefromjpeg("yourImage.jpg"); 
  6.     imagePNG($img); 
  7.     imagedestroy($img); 
  8.    ?> 
  9.  
  10.  
Then as the SRC of your image tags of your HTML code use the above PHP file like this:

Expand|Select|Wrap|Line Numbers
  1.    <img src="imageviewer.php"> 
  2.  
There are currently many websites using this method to protect their photos.
In some websites when you right click on an image and go to properties the only address you can see is a PHP file.

And don't forget that GD must be enabled on the server you are excuting your script on. Most of the servers have GD enabled by default.

Hope this helps you
Oct 5 '08 #3
Atli
5,058 Recognized Expert Expert
Hi.

And alternate way of serving images through a PHP file would be to simply set the appropriate headers and read the contents of the file into the output buffer:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $file = "/path/to/file.jpg";
  3. $info = getimagesize($file);
  4. header("Content-Type: ". $info['mime']);
  5. header("Content-Length: ". filesize($file));
  6. readfile($file);
  7. ?>
  8.  
This would not require the GD extension and would work regardless of the image type.
Also, this should use less memory than it's GD counterpart, as the image would not need to be loaded into memory before it is sent. (Although that would depend on the internals of the readfile function)
Oct 6 '08 #4
samvb
228 New Member
Thanks Guys!

that was very helpful!

U ROCK!
Oct 8 '08 #5
samvb
228 New Member
Hi.

And alternate way of serving images through a PHP file would be to simply set the appropriate headers and read the contents of the file into the output buffer:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $file = "/path/to/file.jpg";
  3. $info = getimagesize($file);
  4. header("Content-Type: ". $info['mime']);
  5. header("Content-Length: ". filesize($file));
  6. readfile($file);
  7. ?>
  8.  
This would not require the GD extension and would work regardless of the image type.
Also, this should use less memory than it's GD counterpart, as the image would not need to be loaded into memory before it is sent. (Although that would depend on the internals of the readfile function)
Dear,
Help out here plz. I actually like ur tip cos it takes less memory, but how wld i ve to it from a function? I need to call it from various files, send paramters, then store the image that i can use in img src?
Oct 16 '08 #6
Atli
5,058 Recognized Expert Expert
It's like bnashenas says. You will have to put this code into a seperate file which is called by an <img> tag's src attribute.

The code acts as an image, so it can not be called directly from your other scrips. You have to let the browser call it as an image.

Like, for example, if I did this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Create a list of available files
  3. // This could be done using a database instead.
  4. $dir = "/path/to/secure/image/location/";
  5. $files = array("image1.jpg", "image2.jpg", "image3.jpg");
  6. $errorImage = "error404.jpg";
  7.  
  8. // Find the requested file from $_GET
  9. if(isset($_GET['id']) && isset($files[$_GET['id']])) {
  10.   $file = $dir . $files[$_GET['id']];
  11. }
  12. else {
  13.   $file = $dir . $errorImage;
  14. }
  15.  
  16. // Print the image
  17. $info = getimagesize($file);
  18. header("Content-Type: ". $info['mime']);
  19. header("Content-Length: ". filesize($file));
  20. readfile($file);
  21. ?>
  22.  
And put this into a file name "imageviewer.php".

I could use this to show the images.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. for($i = 0; $i < 4; $i++) {
  3.   echo '<img src="imageviewer.php?id='. $i .'" alt="Image #'. $i .'" />';
  4. }
  5. ?>
  6.  
The first 3 would show images 0 to 2 from the array, but the last one would show the error image.
Oct 16 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: grahamd | last post by:
Who are the appropriate people to report security problems to in respect of a module included with the Python distribution? I don't feel it appropriate to be reporting it on general mailing lists.
11
by: TC | last post by:
Hello All, I have recently had the pleasure of installing Norton Internet Security 2005 and finding that I can no longer create or open a web-based application in Visual Studio .Net. The IDE...
5
by: Ken Cox [Microsoft MVP] | last post by:
MS has posted this here: http://www.asp.net/faq/ms03-32-issue.aspx Fix for: 'Server Application Unavailable' Error after Applying Security Update for IE...
1
by: Earl Teigrob | last post by:
Background: When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is...
5
by: cdlipfert | last post by:
Our intranet is running under windows integrated security. We have domain users that want to access our intranet site via ssl vpn. SSL VPN can not authenticate against services that run under...
0
by: Charles Leonard | last post by:
I am having yet another issue with Windows Server 2003. This time, the web service (a file import web service) appears to run except for one odd message: "ActiveX component can't create object". ...
0
by: Jay C. | last post by:
Jay 3 Jan. 11:38 Optionen anzeigen Newsgroups: microsoft.public.dotnet.framework.webservices.enhancements Von: "Jay" <p.brunm...@nusurf.at> - Nachrichten dieses Autors suchen Datum: 3 Jan...
10
by: Richard MSL | last post by:
I am having problems working with .net security. I have been attempting to use the Microsoft .Net Framework 2.0 Configuration tool (version 2.0.50727.42), but it won't work for me. I have a simple...
1
by: WebServiceSecurity | last post by:
The issue involves the following technologies: - 1. .NET 2.0 Framework 2. WSE2.0 (WS-Security) 3. X.509 certificates 4. BEA Weblogic 8.1.5
0
by: Anthony Baxter | last post by:
SECURITY ADVISORY Buffer overrun in repr() for UCS-4 encoded unicode strings http://www.python.org/news/security/PSF-2006-001/ Advisory ID: PSF-2006-001 Issue Date: October 12, 2006...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.