如何在javascript文件和php文件之间建立一个桥接代码来保护MySQL信息';s
我有四个文件如何在javascript文件和php文件之间建立一个桥接代码来保护MySQL信息';s,javascript,php,apache,Javascript,Php,Apache,我有四个文件 index.php“主页”,具有使用MySQL数据库的搜索功能。我给数据库打电话 抛出javascript,客户端 fetch.php“包含MySQL连接信息 php来覆盖fetch文件,我使用php代码来 连接 .htaccess文件以阻止对fetch.php文件的任何直接访问 index.phpbridge.phpfetch.phpMysql 我的index.php文件包含以下代码,因为我使用的是JavaScript!.htaccess file阻止index.php文件访问我
我认为您将问题复杂化了,或者您以一种没有帮助的方式编写了
fetch.php
我猜您的fetch.php
中有MySQL函数或类代码,您可以访问和使用这些函数或类代码。类似于:
<?php
define('MYSQL_SERVER','localhost');
define('MYSQL_LOGIN','mylogin');
... and more ...
class DB {
... methods ...
}
?>
我明白了,有没有办法让fetch.php文件中的代码只接受“连接”或被打开“从index.php和关于桥文件,有人提出了建议,但建议不好……我包括了我的获取文件代码,我尝试了你的方法,但还是一样,我把它放在我的code@Someone:确保您的代码与最新编辑的代码相同。如果仍然失败,
var_dump(get_included_files())
向您展示了什么?仍然可以直接访问文件,并且我使用这个var_dump(get_included_files())编辑代码,仍然可以直接访问页面。现在我解决了它,就像您所说的那样,当我直接打开fetch file,空白页面,但是现在index.php根本无法访问数据库
<?php
include 'fetch.php';
?>
<Files ~ "fetch.php">
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
$connect = mysqli_connect("localhost", "example.com", "passowrd", "databasename");
$output = '';
if(isset($_POST["query"]))
{
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM tbl_customer
WHERE CustomerName LIKE '%".$search."%'
OR Address LIKE '%".$search."%'
OR City LIKE '%".$search."%'
<?php
define('MYSQL_SERVER','localhost');
define('MYSQL_LOGIN','mylogin');
... and more ...
class DB {
... methods ...
}
?>
<?php
if (count(get_included_files()) == 1) {
// direct request, do nothing
exit;
// or even redirect somewhere like
header("Location: /");
exit;
}
// has been included, allow rest of script to process
$connect = mysqli_connect("localhost", "example.com", "passowrd", "databasename");
// ... more code below