English 中文(简体)
mysql-php安全
原标题:mysql php security

在我的php页面上,在顶部,我像这样连接到数据库

$db = mysql_connect("mysql.site.com","thedb", "pass"); 
mysql_select_db("dbase",$db); 

这安全吗?有人能扫描并查看我的代码,从而访问数据库吗?

UPDATE

我问的原因是,用户能够访问我的数据库,我很确定这不是通过sql注入。

问题回答

如果您将此代码段移动到文档根目录之外的包含文件中会更好——这将防止人们在您的Web服务器配置错误并开始以纯文本形式提供PHP文件的情况下阅读它。虽然,就其本身而言,它是足够安全的——但不太可能有人故意这样错误配置你的服务器。

如果有人确实可以访问您的代码,那么是的,他们将能够读取密码。

你对此无能为力,但确保这段代码是你的网络根目录上的一个目录会有所帮助。

(即,如果您从文件夹/usr/htdocs/mysite为您的网站提供服务,请将其更改为usr/htdocs/maysite/public

您应该始终应用多层防御

  1. Remove the credentials from the source code and place them outside the web server’s document root.
  2. Restrict access to your database, possibly only via localhost or via socket.
  3. Restrict the user’s privileges to only those necessary.

没关系,重要的是,我可以说,去你的数据库,给那个用户有限的权限,我的意思是只选择、插入、更新和删除它需要的表。。除此之外,我的建议是,用这些信息创建一个文件,并在需要时包含。

如果有人浏览你的代码,就能看到这些信息,但要尽量减少损害影响





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...