How to Protect Your Site Against Hackers
Database-driven sites are vulnerable to hackers, who can (and do) exploit bugs in those programs to gain unauthorized access to your site. The following are some things you can do to help secure your site.
Check all of your website files and folders and make sure that they all have the correct permissions- The standard permission settings for files would be 644 and folders would be 755. Please be aware that these are the standard settings, your site may have different requirements.
Set register_globals to OFF
1.Turn off Display Error/Warning Messages. Set error_display to ZERO.
2.Never run unescaped queries
3.Validate all user inputs. Items on Forms, in URLs and so on
4.Move config.php and files containing Passwords to MySQL to a secure directory outside of the public_html folder
5.Change permissions on any configuration files containing private information such as database passwords or email accounts to 440 so they cannot be written to and so there is no world permissions. If you need to edit them at a later time you will need to change it back to 640.
6.Access Control: You don’t want the user to have access to any Admin function or Clean up scripts
7.The .htaccess file is your friend. Use it to deny access to your site or files.
(We also have an easy IP Deny Manager tool in the cpanel)
8.PHP can parse any valid script, whether it is called foo.php, very_long_name.php.php.php, or even deleteme.bat. Using the default extension of “.php” means that before your hackers start you have already told them you are using PHP. As mentioned, you can use any filename for your scripts – if you are using PHP for every script on your server, consider using the “.html” extension for your scripts and making PHP parse HTML files. You can change your file extension by adding this line to the .htaccess or turn it on via the Apache Handlers in the cPanel (AddHandler application/x-httpd-php5 .html)
To protect against SQL injection attacks Sometimes hackers will try to screw up your database by inserting SQL code into your form input fields. They can for example, insert code that could delete all the data in your database! To protect against this, you need to use this PHP function:
mysql_real_escape_string()
This function escapes (makes safe) any special characters in a string (programmers call text a ’string’) for MySQL.
9.Example: $name = $_REQUEST['name']; $safe_name = mysql_real_escape_string($name);
Now you know the variable $safe_name, is safe to use with your SQL code.
10.Keep the PHP code to yourself. If anyone can see it they can exploit
vulnerabilities.
You should take care to store your PHP files and the necessary passwords to access your MySQL databases in protected files or folders. The easy way to do this is to put the database access passwords in a file with a .inc.php extension (such as config.inc.php), and then place this file in a directory which is above the server’s document root (and thus not accessible to surfers of your site). Then, refer to the file in your PHP code with a require_once command. By doing things this way, your PHP code can read the included file easily but hackers will find it almost impossible to hack your site.
| Print article | This entry was posted by Bibokz on June 5, 2009 at 7:18 am, and is filed under Advice, Ask An Expert, Hack, How To, Malware. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

about 7 months ago
good article , I added you in the ‘Liked’ category.. thanks for sharing the article!
about 9 months ago
I think I will try to recommend this post to my friends and family, cuz it’s really helpful.
about 9 months ago
Thanks for the constructive info and tips concerning website protection.
I personally choose to check and scan my website against application vulnerabilities once a month and i am please of the result and recommendation to close those vulnerabilities.
about 9 months ago
Hi, Congratulations to the site owner for this marvelous work you’ve done. It has lots of useful and interesting data. You work is realy good!
about 9 months ago
Nice comment pinoy web promotion, yes… the site is quite open for well defined hackers. They can manipulate your data using some tweak.
Turning it off can protect to hackers action?
Definitely. It reduces the risk.
about 9 months ago
This blog was made for you guys…
about 9 months ago
Hi, Congratulations to the site owner for this marvelous work you’ve done. It has lots of useful and interesting data.
about 9 months ago
Nice post… See, last time I opened an administrator website it uses software (Joomla) I saw all setting are open or on for Global uses. It is reliable for hacker to hack that site?
What do think? Turning it off can protect to hackers action?