Hello. I hope this is the right section to post in. If it’s not, I apologize. I know C but haven’t programmed in it in a long time. PHP is sorta like C in a lot of ways so I know a little bit of PHP but I still consider myself to be a beginning PHP programmer. My question is simple.
I have a website and I also have Apache2 setup on my local machine to test stuff before I upload it to my domain. Right now, I don’t have much but I do have PHP treating HTML files as if they where all PHP files and I have some PHP code in one of my HTML pages. It connects to a MySQL database with a username and a password. When I load the page, it works fine. If I go to view source, I don’t see the PHP code (which I don’t expect to see, so we’re good there). I want to know though, is this good enough for security? Is there anyway for a hacker to download the PHP code and recover my MySQL password?
I was thinking of ways to make it so PHP files where in a subdirectory and the webpages could access them but users couldn’t. Perhaps using the .htaccess files. This wouldn’t be the greatest solution for me though because I find it easier putting the PHP code inside the HTML files rather than having seperate PHP files.
I’d also like to have some files that start with the word admin that only a select few IP addresses could access. I’ve been using something like what follows down below to do this. I want it so if someone tries to grab the admin files, they can’t tell they’re there. And right now, my rewrite rules don’t work like that. You can tell that my website redirected you. If you try going to a real page that isn’t there, it doesn’t look like you was referred by the website. I can explain that more in detail if it sounds confusing. Any suggestions are greatly welcomed!
# This is my only_allow_certain_IPs_access_to_admin_pages
<FilesMatch "^(admin.*|Admin.*)">
Satisfy all
Order deny,allow
Deny from all
Allow from 192.168.2.2 192.168.2.3
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /srv/www/.htpasswd
AuthGroupFile /srv/www/.htgroup
Require group allowed
</FilesMatch>
# This is my rewrite rules. I tried switching to the rewrite so the user wouldn't get
# an access denied message. If I could figure out how to redirect without them knowing they
# been redirected, this would be the way I'd want to go. I'd just have it setup for admin files.
# I could even keep PHP code in .php files that are in a subdirectory and then keep the admin
# stuff in an admin subdirectory to make things easier.
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^192\.168\.2\.2
RewriteCond %{REMOTE_ADDR} !^192\.168\.2\.3
RewriteRule ^.*$ http://192.168.2.2 [R=404,L]
Thank you.