PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 20th, 2012, 11:50 AM
jrfiol jrfiol is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 jrfiol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 20 sec
Reputation Power: 0
PHP5 - Prevent access to files using URL

Hello, I am new to the forum and have been tasked with adding functionality to an existing dynamic web page. Limited php coding experience.

I have been successful in creating a link, for logged in users to an xml/xsl file:

PHP Code:
<?php
echo "../patientfiles/".$_SESSION['Login']."/ccd".$_SESSION['Login'].".xml";
?>


however, if a user copies the url, he/she may paste it in the browser at any time and access the file.

is there a way to display the file in the browser, without giving up the path?

Kindest regards,

Reply With Quote
  #2  
Old November 20th, 2012, 12:02 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 4 h 18 m 43 sec
Reputation Power: 581
What is your objective in preventing the user from copy/pasting the URL? That will determine how to solve the problem.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old November 20th, 2012, 12:11 PM
jrfiol jrfiol is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 jrfiol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 20 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
What is your objective in preventing the user from copy/pasting the URL? That will determine how to solve the problem.


The file is of sensitive info. My objective is to make sure that no one can see the file unless they are logged in.

Each user will have his own file, in his own directory. But a tricky user could change the url to see another users information.

The user can download, email the file...whatever. I just need the file to only be available from our server if a user is logged in and clicks on the link.

PD - I really appreciate your quick response!

Last edited by jrfiol : November 20th, 2012 at 12:12 PM. Reason: adding info

Reply With Quote
  #4  
Old November 20th, 2012, 12:16 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 4 h 18 m 43 sec
Reputation Power: 581
That is not a PHP function. Files that require authentication are protected by your settings in your HTTPD configuration. Are you using Apache or is this Windows?

Reply With Quote
  #5  
Old November 20th, 2012, 12:17 PM
jrfiol jrfiol is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 jrfiol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 20 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
That is not a PHP function. Files that require authentication are protected by your settings in your HTTPD configuration. Are you using Apache or is this Windows?


apache

Reply With Quote
  #6  
Old November 20th, 2012, 12:24 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 4 h 18 m 43 sec
Reputation Power: 581
Then you need to do a few things.

1) Implement SSL
2) Use mod_rewrite to force https
3) Set up authentication in Apache to restrict access to those files.

Reply With Quote
  #7  
Old November 20th, 2012, 12:30 PM
jrfiol jrfiol is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 jrfiol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 20 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Then you need to do a few things.

1) Implement SSL
2) Use mod_rewrite to force https
3) Set up authentication in Apache to restrict access to those files.


3) Set up authentication in Apache to restrict access to those files. - by using htaccess? i have, but cannot figure out how to automate the login.

my plan is to use a generic login account for all sub-directories and files. but have failed miserably! i cannot submit the usr/pwd using plain text.

Is there a way to embed the usr/pwd for this directory in the script without exposing it?

Reply With Quote
  #8  
Old November 20th, 2012, 12:46 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 4 h 18 m 43 sec
Reputation Power: 581
Sort of. While .htaccess is a solution, it is my understanding that it is depreciated and everything you want to do should be handled in your Apache configuration files. This thread is really beyond the scope of this forum. You don't have to worry about username and password exposure. That is all handled by Apache depending on your authentication method and there are several. You can start here.

Reply With Quote
  #9  
Old November 20th, 2012, 01:51 PM
jrfiol jrfiol is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 jrfiol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 9 m 20 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Sort of. While .htaccess is a solution, it is my understanding that it is depreciated and everything you want to do should be handled in your Apache configuration files. This thread is really beyond the scope of this forum. You don't have to worry about username and password exposure. That is all handled by Apache depending on your authentication method and there are several. You can start .


Thanks a lot, really appreciate the manual.

I have configured the user/password for the directory successfully. But i want to use only one user account, and include it in the script that calls the file.

Has that been done?

Reply With Quote
  #10  
Old November 20th, 2012, 02:04 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 4 h 18 m 43 sec
Reputation Power: 581
You want all users to access it with the same account? That won't work because every user will have access to every protected file. The restriction is based on user name.

Not sure what you mean by "include it in the script that accesses the file". If you've implemented authentication correctly, your script does not have to worry about it. Apache will prevent unauthorized access as well as prompt for the login.

Last edited by gw1500se : November 20th, 2012 at 02:08 PM.

Reply With Quote
  #11  
Old November 20th, 2012, 02:20 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 297 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 45 m 39 sec
Reputation Power: 5
I'm not too sure your directory structures, but is this file in a directory accessibly via the internet? From the way your intent sounds, I would just keep these files in a location NOT accessible via the internet, so your php must locally fetch the file's content using your logged in user's credentials and offer it back to the user.

Reply With Quote
  #12  
Old November 20th, 2012, 02:29 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 4 h 18 m 43 sec
Reputation Power: 581
It is my understanding there are multiple files and multiple users. Much more secure and less prone to holes to use built-in authentication and let Apache worry about it.

Reply With Quote
  #13  
Old November 20th, 2012, 05:24 PM
msteudel's Avatar
msteudel msteudel is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712 msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
Quote:
Originally Posted by jrfiol
Hello, I am new to the forum and have been tasked with adding functionality to an existing dynamic web page. Limited php coding experience.

I have been successful in creating a link, for logged in users to an xml/xsl file:

PHP Code:
<?php
echo "../patientfiles/".$_SESSION['Login']."/ccd".$_SESSION['Login'].".xml";
?>


however, if a user copies the url, he/she may paste it in the browser at any time and access the file.

is there a way to display the file in the browser, without giving up the path?

Kindest regards,


So a more PHP centric solution could be something like this:

1. User logs in, at login their authentication status is saved into their session
2. Instead of generating a link to specific file, you point it to a php file that checks if the user is logged in, then it reads and outputs the xml to the browser if they are logged in.

e.g.

PHP Code:
<?php 

session_start
();

if( 
$_SESSION['youruserisauthenticaed'] === true ) {
    
/// read in xml file and output it to browser
}
else {
    
/// notify user is not authenticated and provide them a link to login
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Prevent access to files using URL

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap