943,678 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 528
  • PHP RSS
Aug 17th, 2009
0

PHP Security

Expand Post »
Hello Guys,

I have bult a php site, and going live soon some questions first of all from what i read i need to have a .htaccess file in which it has turn of register_global and disable errors do i need to put anything further? I also have a admin section which is password protected from my hosting company, is that safe? after reading i am getting loads of different information can someone please help me with what i need to follow (tutorial)

thank you
Reputation Points: 10
Solved Threads: 0
Light Poster
NoID is offline Offline
49 posts
since Jul 2009
Aug 17th, 2009
0

Re: PHP Security

Quote ...
I have bult a php site, and going live soon some questions first of all from what i read i need to have a .htaccess file in which it has turn of register_global and disable errors do i need to put anything further?
I believe that is a php.ini file not .htaccess but doing that in the php.ini will work fine.
Quote ...
I also have a admin section which is password protected from my hosting company, is that safe?
Well I would recommend that instead of using a .htaccess file to password protect the files, instead use actual php code to protect the data and of course any sensitive data would be in a database where only php can access it when programmed securely.
Quote ...
after reading i am getting loads of different information can someone please help me with what i need to follow (tutorial)
Perhaps a google search will answer that.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Aug 17th, 2009
0

Re: PHP Security

If you have any classes, functions, ect. you need to move them behind the document root (same folder as public_html on most hosts). Then you just included them.

You need to add a php.ini file and protect it with .htaccess. This means you put your php configurations in the php.ini and disable people from viewing in their browser via .htaccess.

In your .htaccess file:
PHP Syntax (Toggle Plain Text)
  1. <Files .htaccess>
  2. order allow,deny
  3. deny from all
  4. </Files>
  5. <Files php.ini>
  6. order allow,deny
  7. deny from all
  8. </Files>

Also disable the directory listing so people cannot see what you have on the server.

PHP Syntax (Toggle Plain Text)
  1. Options -Indexes

Here is a good php.ini example:
PHP Syntax (Toggle Plain Text)
  1. output_buffering = Off
  2. safe_mode = Off
  3. error_reporting = E_ALL & ~E_NOTICE
  4. display_errors = Off
  5. log_errors = On
  6. ignore_repeated_errors = On
  7. html_errors = Off
  8. error_log = /home/username/logs/php_error_log
  9. default_charset = "utf-8"
  10. file_uploads = On
  11. upload_max_filesize = 100MB
  12. post_max_size = 150MB
  13. allow_url_fopen = On
  14. register_globals = Off
  15. magic_quotes_gpc = Off
  16. session.name = SESSID
  17. disable_functions = exec,shell_exec,passthrough,eval,phpinfo

php.ini usually only works on a per directory basis so if you have multiple folders that need the same configuration, you need copy the same php.ini into each directory. (Spent hours finding this one out)

If you do not have uploads on the site, make sure you turn file uploads to 'off'. Also, if you don't need to access remote urls then turn off allow_url_fopen.

Make sure you leave the error logging part of the ini file. This will make it so all errors are logged to a central location and not in the directory of the file which had the error. The reason for this is so hackers cannot see the errors of the site, which might help them hack it.

If you use sessions, make sure you change the location of where they are stored. If another account is compromised on the server, a hacker could get into the tmp directory where your sessions are and steal info/hijack a session.

Here is a link on changing it: http://us3.php.net/manual/en/functio...-save-path.php
You can also do it through php.ini.

Make sure the directory where you are storing the sessions is not accessible to the public.

I wouldn't use http authentication with a .htpasswd file. At least use a database to store the login info. A login system with php (like cwarn23 said) would be best in my opinion. I posted a good example at: http://www.daniweb.com/forums/thread212083.html
Last edited by kkeith29; Aug 17th, 2009 at 2:45 pm.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Aug 17th, 2009
0

Re: PHP Security

Quote ...
and disable people from viewing in their browser via .htaccess.
PHP Syntax (Toggle Plain Text)
  1. error_log = /home/username/logs/php_error_log

I understand it will save it in logs folder, but what does file extention does it need to be?
What i dont understand is, cant i just disable it rather than saving it? I mean lets say my website is done and i will never update it (which isnt the case lol) can i not just disable it, can you please tell me why i need it and if so can i not save error to mysql database?


Thank you for your information, it has been printed and sace , I think its now time to learn PHP correctly rather than doing shortcuts.
Reputation Points: 10
Solved Threads: 0
Light Poster
NoID is offline Offline
49 posts
since Jul 2009
Aug 17th, 2009
0

Re: PHP Security

It doesn't need one. You can make one up if you want to.

Error logs can tell you a lot. Errors shouldn't be shown to your users, so I something goes wrong you need to be able to find the error somewhere. Always have the error log on.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Aug 17th, 2009
0

Re: PHP Security

You can also use

php Syntax (Toggle Plain Text)
  1. ini_set("register_globals", "off");

rather than use .htaccess or if you can't amend the php.ini file
Reputation Points: 15
Solved Threads: 17
Junior Poster
phper is offline Offline
189 posts
since Nov 2006
Aug 18th, 2009
0

Re: PHP Security

change your php.ini file
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Aug 18th, 2009
0

Re: PHP Security

Hello,

I would like to ask, if i will be able to save all errors to mysql rather than a log file.

also is it possible for me to be able to save any errors which end users make for example, a user enters user name and enters wrong password, can i save that error?
Reputation Points: 10
Solved Threads: 0
Light Poster
NoID is offline Offline
49 posts
since Jul 2009
Aug 20th, 2009
0

Re: PHP Security

Click to Expand / Collapse  Quote originally posted by NoID ...
Hello,

I would like to ask, if i will be able to save all errors to mysql rather than a log file.

also is it possible for me to be able to save any errors which end users make for example, a user enters user name and enters wrong password, can i save that error?
The easiest way to make it save into a mysql database is simply by setting up a cron job to automatically transfer the data from the error log file to the database. And as for the error of wrong passwords, simply append to the log file which the cron task will then take care of. Hope that theory helps.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: my code are wrong and I don't no why? I'm desesperated!!!! Please help me!!!
Next Thread in PHP Forum Timeline: Smarty Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC