Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Secure User Area

Featured Replies

Hi,

 

I am the Web Admin for my old CSM's new company and on his website he would like to have a feature where his clients can login with provided credentials, required to change their password at login, and can view personal reports uploaded by myself or themselves. The area cannot be shared, nor can it be accessible by others.

 

I have a basic understanding of PHP and MYSQL, but I can pretty much make the login/change password and logout feature, it is just the report uploading for that user I do not know how to do.

 

Any help would be appreciated.

 

If you would prefer, email a reply to my email address please: richy.roo@hotmail.co.uk.

 

Thank you.

 

Other info:

Webhost is Justhost.com

MYSQL enabled.

PHP Enabled.

No restrictions to DBs.

  • Author

File uploads are covered in the PHP manual.

 

http://www.php.net/manual/en/features.file-upload.post-method.php

That covers uploading yes, but how do I upload it so only that individual can see it and download/view it online? How do I make it secure and appear as a link for them to see?

 

Thanks.

That covers uploading yes, but how do I upload it so only that individual can see it and download/view it online? How do I make it secure and appear as a link for them to see?Thanks.

 

One way of doing it: Have a table in the database which stores the paths to the documents uploaded (give them random names to make the more secure), and make a column in the document table (such as client_id) which gives each row an id that corresponds to the id of the user for that document. Then in the client area just show the documents where client_id = the id of the logged in user

1) How sensitive are the documents (will the world end if someone got to them :D)?

 

2) What type of documents are they (.doc,.pdf....) ?

 

The reason I ask is because you would use very different methods depending on the answers to the question 1 and if the answer to question 2 is simple .doc files then rather copying and pasting the content to a RTE in the browser and sending to a database might be easier.

  • Author

1) How sensitive are the documents (will the world end if someone got to them :D)?

 

2) What type of documents are they (.doc,.pdf....) ?

 

The reason I ask is because you would use very different methods depending on the answers to the question 1 and if the answer to question 2 is simple .doc files then rather copying and pasting the content to a RTE in the browser and sending to a database might be easier.

Information is information, it is sensitive regardless. It discloses information about companies and businesses. And it would be Word, Excel, Pdfs.

  • Author

One way of doing it: Have a table in the database which stores the paths to the documents uploaded (give them random names to make the more secure), and make a column in the document table (such as client_id) which gives each row an id that corresponds to the id of the user for that document. Then in the client area just show the documents where client_id = the id of the logged in user

 

Are you able to help me out with any code? Also would I have to manually edit the table for every new user I create, or can I create an HTML form which only I have access to which I can use to create accounts which add to the table automatically with MySQL?

Information is information, it is sensitive regardless. It discloses information about companies and businesses. And it would be Word, Excel, Pdfs.

 

okay then, it is actually quite relevant, simply having "random" names will make then fairly easy to access with a little bit of effort, .httaccess is the proper way to secure folders and restrict access.

Are you able to help me out with any code? Also would I have to manually edit the table for every new user I create, or can I create an HTML form which only I have access to which I can use to create accounts which add to the table automatically with MySQL?

Yes that can be done. Just create a form that inserts data into the database, fairly easy if you know some mysql. For more info read up about it here

I'd rename the file using uniqid() and store it in a directory outside of the web root. Make a database record identifying the id to the user id. Then you can serve with PHP or even better mod_xsendfile.

  • Author

Okay thank you everybody.

As Jock says, storing it outside of the root and using a php script to retrieve it is the key. Combine that with rallport's bullet list and you should be pretty damn secure!

  • Author

Wow great thank you!

 

Could you maybe show me some code possibly to help with referring indirectly to files?

 

Thanks.

It's actually a lot more simple than it sounds. Typing the address of a file in the address bar requires the file to be inside the public root folder so putting something outside it means you can't access it. But, a php file running on your server can access it e.g. php can refer to a file as "../hiddenfiles/file.pdf"

  • Author

It's actually a lot more simple than it sounds. Typing the address of a file in the address bar requires the file to be inside the public root folder so putting something outside it means you can't access it. But, a php file running on your server can access it e.g. php can refer to a file as "../hiddenfiles/file.pdf"

 

Ah right, that explains a lot then! I knew you could not normally access it, but if php can then great! Thanks, you are a great help.

You just create a download.php file and use file_get_contents() and echo the file as application/pdf (for a pdf of course) then you can make your link point to download.php?file=123 and put all of your authorisation checking in the download.php file too.

  • Author

You just create a download.php file and use file_get_contents() and echo the file as application/pdf (for a pdf of course) then you can make your link point to download.php?file=123 and put all of your authorisation checking in the download.php file too.

 

You should come work for me!!

 

I can pay you in beer? :D

 

Haha thanks again.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.