I have four files.
- index.php "the main page" with search function that use MySQL databse. and I call the database throw javascript, client side.
- fetch.php "contain MySQL connections info's.
- bridge.php to cover fetch file, and I'm using php code to make the connection.
- .htaccess file to block any direct access to the fetch.php file.
index.php<--->bridge.php<--->fetch.php<--->Mysql
My index.php file contain this code below, and because I'm using JavaScript! .htaccess file blocked index.php file from accessing my fetch.php file, javascript is "client side"
<script>
$(document).ready(function(){
function load_data(query)
{
$.ajax({
url:"bridge.php",
method:"post",
data:{query:query},
success:function(data)
{
$('#result').html(data);
}
});
}
So I made my javascript code call the bridge.php file, and the bridge.php file call the fetch.php file throw PHP language, to make all this work.
So my bridge.php file code:
<?php
include 'fetch.php';
?>
Now no one can access fetch.php directly .htaccess file block any direct connection throw the browser but if I call the file bridge.php throw the browser it will open the database! that's doesn't solve anything! what I'm doing wrong?
This is the code of my .htaccess file:
<Files ~ "fetch.php">
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
And this is how my fetch file call MySQL:
$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."%'