【发布时间】:2015-11-10 10:42:20
【问题描述】:
举个例子:
http://domain.com/main.php(then the database file here).
我什至不知道那叫什么,但我在上面找不到任何东西。
【问题讨论】:
-
我不知道我是否正确,但您不要想将您的数据库名称放在链接中...
举个例子:
http://domain.com/main.php(then the database file here).
我什至不知道那叫什么,但我在上面找不到任何东西。
【问题讨论】:
出于安全原因,不建议将您的数据库名称放在查询字符串中的 GET 请求中。但是,如果您仍然需要它,您可以这样做:
http://domain.com/main.php?database_name=MyDatabase
然后是 PHP 代码:
<?php
$databaseName = $_GET['database_name'];
?>
【讨论】:
当然可以使用GET参数
您可以通过以下方式在 PHP 中获得:
$_GET['foo'];
我真的不知道你为什么要在链接中传递数据库名称。当然,它可以是一个参数,但它太不安全了!
更新:您可以使用更多/多个数据库,但使用配置文件。连接名称或数据库名称未在 url 中传递。
.../main.php?state=demo&type=1, .../main.php?state=demo&type=2等
if ($_GET['state'] == 'demo')
{
switch ($_GET['type'])
{
case 1:
$databaseName = 'demo_type_1';
break;
case 2:
$databaseName = 'demo_type_2';
break;
default:
throw new Exception('Wrong demo specified');
}
// connect to database with the name in $databaseName
}
else
{
// Other connection
}
更好的是将演示状态设置为会话,这样你就可以在没有url的情况下读出它(更安全)
【讨论】: