473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PHP and MySQL Security for a Newb

Ok, I'm new to PHP and MySQL. I've been going through tutorials, reading the
documentation, and looking through web sites. PHP to me seems great! With
MySQL it seems even better.

However, I'm an experienced C++ programmer. This has allowed me to see many
potential areas where the security of a server can be compromised through
loopholes in PHP. Granted, with the right knowledge these potential threats
can be avoided. But I've just started and while I may have found some,
certainly I haven't seen all or at least the most common mistakes.

So then, what I'm asking for is a list, based on the experiences of the PHP
and MySQL community at large, of potential areas to watch out for. Basically
a Dos and Don'ts list, mostly with the Don'ts. If there is a web site that
is consider the source for this sort of info, please let me know. I have
seen many, but so far have not found a definitive one.

Also, I have some specific questions:

Everytime I connect to a database, I have to supply a username and password
in my PHP file (duh). This bothers me, cause it seems like someone could
easily find there way to this file. I guess I have two questions. A normal
user on the web with no special access to my server (assuming they don't
have some weird backdoor they found) can't view the PHP file, right? Because
it is executed and translated on the server end before every leaving the
server to go to the user and pop up on their browser. They can't somehow get
at the original source or get the password to the database, right?

If I do give somehow access to the server (let's say using FTP), I have to
make sure not to give them access to my PHP stuff. If they do want their own
database, what should I do? I'm assuming the best course of action is to
create a database for them and a new MySQL username for them, giving only
that username access to that database.

Thanks for help.
Jul 16 '05 #1
2 2333
If you really are into security, the most important part is to validate
every single entry. When processing a form, validate that it come from
your website. Validate the data and where it came from.

Don't show filenames on the outside. Many beginners do stuff like:
page.php?content=thatpage.inc
Which is obviously unsecure.

Ad for the MySQL part. You have to provide the username or password, if
you don't want to, you can use defautl ones but that's just less secure.
It depends on what kind of website you are working on, but if you use a
user table, make sure the passwords are hashed using either md5 or sha1.
Encrypt and/or obfuscate the email adresses and credit card numbers(if
any). That way, even if someone gain acces to your database, the data
will be safe. If only an administration section can modify the data in
the database, you might want to place that administration on an other
server using SSL connection, or even better, make it accessible only
from local access (of course, that restrains flexibility). Pages that
only view data should use a restrained MySQL connection (which can only
read, or write trivial informations).

Make backups often, don't keep informations you don't need. Destroy old
credit card numbers you don't need anymore as soon as you can.

There are different levels of security, what do you need it for?

Xizor wrote:
Ok, I'm new to PHP and MySQL. I've been going through tutorials, reading the
documentation, and looking through web sites. PHP to me seems great! With
MySQL it seems even better.

However, I'm an experienced C++ programmer. This has allowed me to see many
potential areas where the security of a server can be compromised through
loopholes in PHP. Granted, with the right knowledge these potential threats
can be avoided. But I've just started and while I may have found some,
certainly I haven't seen all or at least the most common mistakes.

So then, what I'm asking for is a list, based on the experiences of the PHP
and MySQL community at large, of potential areas to watch out for. Basically
a Dos and Don'ts list, mostly with the Don'ts. If there is a web site that
is consider the source for this sort of info, please let me know. I have
seen many, but so far have not found a definitive one.

Also, I have some specific questions:

Everytime I connect to a database, I have to supply a username and password
in my PHP file (duh). This bothers me, cause it seems like someone could
easily find there way to this file. I guess I have two questions. A normal
user on the web with no special access to my server (assuming they don't
have some weird backdoor they found) can't view the PHP file, right? Because
it is executed and translated on the server end before every leaving the
server to go to the user and pop up on their browser. They can't somehow get
at the original source or get the password to the database, right?

If I do give somehow access to the server (let's say using FTP), I have to
make sure not to give them access to my PHP stuff. If they do want their own
database, what should I do? I'm assuming the best course of action is to
create a database for them and a new MySQL username for them, giving only
that username access to that database.

Thanks for help.


Jul 16 '05 #2
Whatchyoo talkin `bout, Louis-Philippe Huberdeau?
Ad for the MySQL part. You have to provide the username or password, if
you don't want to, you can use defautl ones but that's just less secure.


As far as MySQL is concerned, use a separate machine for it, and only
allow queries from the server. That's pretty secure.

--
Caution: breathing may be hazardous to your health.
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: knoak | last post by:
Hi there, I have a small question: I have a table with lots of rows in it. Of course all have a different id, but each can be assigned to a certain category. Categories correspond with 1 - 10....
2
by: marko2 | last post by:
I have debian running and this is how I have it setup # ls -ld /var/lib/mysql drwxr-xr-x 4 mysql mysql 4096 Aug 19 11:29 /var/lib/mysql I was shown how to setup a password for...
2
by: zzapper | last post by:
Hi, Although I'm gradually getting the hang of working with MySql, can do a pretty mean query!! I realise I know nowt about security. Is security basically done outside MySQL ie with https:// and...
1
by: cover | last post by:
Hi, Is there a site that anyone knows of, that shows creating a MySQL database from input through output is concerned? I'd LOVE to see a tutorial that included the interface for input, the usable...
2
by: KaHuNa | last post by:
this code works perfectly when i use it on the server where mySQL is installed, but i have a security error when i use it on a client computer. I don't know how i can change that. using...
5
by: NewbieSupreme | last post by:
I installed Apache 2.0.58, tested it, got the "working" page. Installed MySQL 5.0.22, and didn't really see how to test that, but there is a mysql process running in the task manager. Ran through...
12
by: mistral | last post by:
phpMyAdmin 2.6.2 problem: can no connects to mySQL database: each time shown error #1045 - Access denied for user 'username'@'192.168.1.2' (using password: YES) Is seems, this is most common...
2
Paks
by: Paks | last post by:
Hello, I have a quick little question about the MySQL-command LEFT(columnName,int). My question is if there's a counterpart in PostgreSQL for this command and what it is? What I want to do is...
0
Coldfire
by: Coldfire | last post by:
Since i cannot show the differences in a two-column like table. I am first putting MS SQL Server 2005 and then MySQL 5.x. MS SQL Server 2005 Brief Overview - SQL Server is a full-fledged...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.